Shell one-liner: Difference between revisions

From Rosetta Code
Content added Content deleted
(add CL and E examples)
(clarify task description, say something about the "which shell?" question)
Line 1: Line 1:
{{task|Programming environment operations}}
{{task|Programming environment operations}}


Show how to specify and execute a short program in the language from a command shell.
Execute one line of code from the shell.

Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different command argument syntax, or the systems those implementations run on have different styles of shells, it would be good to show multiple examples.


=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==

Revision as of 00:51, 9 February 2009

Task
Shell one-liner
You are encouraged to solve this task according to the task description, using any language you may know.

Show how to specify and execute a short program in the language from a command shell.

Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different command argument syntax, or the systems those implementations run on have different styles of shells, it would be good to show multiple examples.

ALGOL 68

Works with: ALGOL 68G version Any - tested with release mk15-0.8b.fc9.i386

<lang>$ a68g -e 'print(("Hello",new line))'</lang>

Hello

C

Not orthodox, but working... (Do not run it into a directory where files with names T0.c and T exist!)

<lang> $ echo -e "#include<stdio.h>\nint main(){printf(\"Hello\\\n\");return 0;}" >T0.c &&

 gcc T0.c -o T && ./T && rm -f T0.c T

</lang>

Hello

Common Lisp

Varies by implementation; in SBCL,

<lang sh>sbcl --noinform --eval '(progn (princ "Hello") (terpri) (quit))'</lang>

E

<lang sh>rune --src.e 'println("Hello")'</lang>

The --src option ends with the the filename extension the provided type of program would have:

rune --src.e-awt 'def f := <swing:makeJFrame>("Hello"); f.show(); f.addWindowListener(def _{to windowClosing(_) {interp.continueAtTop()} match _{}}); interp.blockAtTop()'

Haskell

<lang> $ ghc -e 'putStrLn "Hello"' Hello </lang>

J

<lang> $ jconsole -js "exit echo 'Hello'" Hello </lang>

OCaml

<lang> $ ocaml <(echo 'print_endline "Hello"') Hello </lang>

Perl

<lang> $ perl -e 'print "Hello\n"' Hello </lang>

PHP

assuming you have the PHP CLI (command-line interface) installed, not just the web server plugin <lang> $ php -r 'echo "Hello\n";' Hello </lang>

Python

<lang> $ python -c 'print "Hello"' Hello </lang>

Ruby

<lang> $ ruby -e 'puts "Hello"' Hello </lang>