Anonymous user
Shell one-liner: Difference between revisions
→{{header|Binary Lambda Calculus}}
imported>Tromp |
|||
(12 intermediate revisions by 8 users not shown) | |||
Line 25:
=={{header|ACL2}}==
<
=={{header|Ada}}==
Line 31:
'''under a unixoid shell''' (bash, sh, ...)
<
Note that this mercilessly overwrites and later deletes any files x.adb, x.ali, x,o and x in the current directory.
=={{header|Aikido}}==
<
=={{header|Aime}}==
<
=={{header|ALGOL 68}}==
{{works with|ALGOL 68G|Any - tested with release mk15-0.8b.fc9.i386 - Interpret straight off}}
<
Output:
<pre>Hello</pre>
{{works with|ELLA ALGOL 68|Any - tested with release 1.8.8d.fc9.i386 - translate to [[C]] and then compile and run}}
For an [[ELLA ALGOL 68]] one-liner, merge these lines of shell code:
<
a=/tmp/algol$$ s=/usr/share/algol68toc;
echo -e "PROGRAM algol$$ CONTEXT VOID\nUSE standard\nBEGIN\n$code\nEND\nFINISH\n" > $a.a68 &&
a68toc -lib $s -dir $s -uname TMP -tmp $a.a68 && rm $a.a68 &&
gcc $s/Afirst.o $a.c -l{a68s,a68,m,c} -o $a && rm $a.c &&
$a; rm $a</
Output:
<pre>Hello</pre>
=={{header|AppleScript}}==
<
=={{header|Arturo}}==
Line 64:
You may run any arbitrary code string directly using the <code>-e</code> (or <code>--evaluate</code>) flag:
<
{{out}}
Line 72:
=={{header|AWK}}==
Maybe the most common way one can use awk is from the command line for one-liners, feeding the interpreter with an input.
<
A more "complex" and "real" example:
<
''Select'' field 2 and 4 of lines matching the regular expression <tt>/IN/</tt> (i.e. where IN appears)
Line 81:
=={{header|BASIC}}==
The name of the BASIC executable will vary (common ones are ''basic'', ''bas'', and ''bwbasic''), but in general, a short program can be piped to the interpreter like any other language:
<
Note that under Windows (and presumably DOS) the two apostrophes (a.k.a. single quotes) should be omitted, since Windows doesn't remove them from the piped text (and the apostrophe is the comment character in many modern BASICs):
<
Also, some popular interpreters (including [http://www.moria.de/~michael/bas/ Michael Haardt's '''bas'''] and [[Chipmunk Basic]]) will include an extra prompt before exiting unless you include <code>exit</code> or <code>system</code> (depending on the specific interpreter's syntax). This sample output shows both with and without <code>system</code> in bas:
Line 104:
On the ZX Spectrum, the ROM basic allows direct commands to be entered from the system prompt:
<
==={{header|BaCon}}===
Line 111:
then compile a.bac using bacon then run ./a
<
echo "PRINT \"Hello World\" " > a.bac && bacon a && ./a
</
Converting 'a.bac'... done, 2 lines were processed in 0.003 seconds.
Line 122:
=={{header|Bc}}==
<
{{out}}
<pre>Hello 123</pre>
=={{header|Binary Lambda Calculus}}==
Several such one liners are shown on https://www.ioccc.org/2012/tromp/hint.html, such as
<syntaxhighlight lang="bash">echo "*Hello, world" | ./tromp</syntaxhighlight>
<syntaxhighlight lang="bash">echo "00010001100110010100011010000000010110000010010001010111110111101001000110100001110011010000000000101101110011100111111101111000000001111100110111000000101100000110110" | ./tromp -b | head -c 70</syntaxhighlight>
=={{header|Bracmat}}==
Line 130 ⟶ 135:
DOS:
<
Linux:
<
Output:
<pre> 1
Line 158 ⟶ 163:
=={{header|Burlesque}}==
<syntaxhighlight lang="text">
Burlesque.exe --no-stdin "5 5 .+"
</syntaxhighlight>
</lang>▼
Using the official interpreter.
Line 169 ⟶ 174:
delete it to avoid to call another shell/system dependent command/program). The
''current directory'' is not specified by <tt>./</tt> in every system...
<
=={{header|C sharp|C#}}==
Line 175 ⟶ 180:
Requires PowerShell 2:
<
> [HelloWorld]::SayHi()
Hi!</
=={{header|Clojure}}==
Line 184 ⟶ 189:
clj-env-dir comes with clojure-contrib.
<
#'user/add2
42</
=={{header|CMake}}==
This only works with [[Unix]] systems that have the device node <code>/dev/stdin</code>.
<
=={{header|COBOL}}==
Works with GnuCOBOL 2.0 or later
<
Longer, but avoids two relaxed syntax warnings:
<
=={{header|Common Lisp}}==
Line 205 ⟶ 210:
{{works with|SBCL}}
<
{{works with|CLISP}}
<
=={{header|D}}==
{{works with|D|2}}
requires [https://github.com/D-Programming-Language/tools/blob/master/rdmd.d rdmd]
<
<pre>Hello World!</pre>
=={{header|Dc}}==
<
=={{header|Delphi}}==
Run in cmd.exe.
<
The output has the default Delphi header, before the output of executable ("Hi").
=={{header|E}}==
<
The <code>--src</code> option ends with the the filename extension the provided type of program would have:
<syntaxhighlight lang="text">rune --src.e-awt 'def f := <swing:makeJFrame>("Hello"); f.show(); f.addWindowListener(def _{to windowClosing(_) {interp.continueAtTop()} match _{}}); interp.blockAtTop()'</
=={{header|Elixir}}==
<
Hello, World!</
=={{header|Emacs Lisp}}==
<
Or another example that does something useful: indent a [[C]] source file:
<
=={{header|Erlang}}==
Erlang always starts other applications that can run in parallel in the background, and as such will not die by itself. To kill erl, we sequentially run the 'halt' function from the 'erlang' module (the -S is there to guarantee 'halt' will be evaluated after the io function).
<
hello</
=={{header|F_Sharp|F#}}==
<
Hello from F#</
=={{header|Factor}}==
<
=={{header|Forth}}==
{{works with|GNU Forth}}
<
Hello</
=={{header|Fortran}}==
This example, stolen from the [[Shell_one-liner#c|c]] example is subject to the same caveats. While contrived, FORTRAN as a one liner can easily handle some unique tasks. Let's plot a Bessel function:
<
$ gawk 'BEGIN{print"write(6,\"(2(g12.3,x))\")(i/10.0,besj1(i/10.0), i=0,1000)\nend";exit(0)}'|gfortran -ffree-form -x f95 - | gnuplot -p -e 'plot "<./a.out" t "Bessel function of 1st kind" w l'
</syntaxhighlight>
</lang>▼
Sorry, I don't know how to upload my jpeg file for the Image tag. Let's use the dumb display instead.
<pre>
Line 288 ⟶ 293:
=={{header|Free Pascal}}==
The FPC (Free Pascal compiler) comes with the utility <tt>instantfpc(1)</tt> or <tt>ifpc(1)</tt> for short (Debian or FreeBSD package <tt>fpc-utils</tt>):
<
=={{header|FreeBASIC}}==
<
Shell "echo For i As Integer = 1 To 10 : Print i : Next > zzz.bas && fbc zzz.bas && zzz"
Sleep</
{{out}}
Line 315 ⟶ 320:
The <CODE>-e</CODE> command-line option executes a command or commands and prints its value.
<
{{out}}
Line 324 ⟶ 329:
=={{header|FutureBasic}}==
This is forcing the issue. FB has much more elegant ways of interacting with the Unix Shell.
<
window 1,,(0,0,160,120):Str255 a:open "Unix",1,"cal 10 2018":do:line input #1,a:print a:until eof(1):close 1:HandleEvents
</syntaxhighlight>
</lang>▼
Output
Line 341 ⟶ 346:
=={{header|Gambas}}==
'''[https://gambas-playground.proko.eu/?gist=4385adf6a841435779a7afff3dadb58b Click this link to run this code]'''
<
Shell "echo Hello World"
End</
Output:
<pre>
Line 352 ⟶ 357:
=={{header|Gema}}==
<
Hello</
=={{header|Go}}==
<
{{out}}
<pre>
Line 364 ⟶ 369:
=={{header|Groovy}}==
{{works with|UNIX Shell}}
<
Hello</
{{works with|Windows Command Interpreter}}
<
Hello</
=={{header|Haskell}}==
<
Hello</
=={{header|Huginn}}==
Result of an expression is printed by default:
<
Output:
<pre>"Hello"</pre>
Even with an explicit `print` function was used:
<
Output:
<pre>Hello
none</pre>
Unless the last expression ended with a semicolon:
<
Output:
<pre>Hello</pre>
Line 394 ⟶ 399:
These examples work with posix shells.
<
<
=={{Header|Insitux}}==
When Insitux has been already been installed system-wide (<code>npm i -g insitux</code>).
<pre>
$ npx ix -e "(+ 2 2)"
{{out}}
<pre>
4
=={{header|J}}==
<
Hello
</syntaxhighlight>
Here, the (empty) result of <code>echo</code> is used as the exit code argument for <code>exit</code>. And, since it's empty, the the default exit code of 0 is what's actually used. The exit command here is used to prevent the default behavior of jconsole (which is to start the J [[wp:Command_shell|command shell]]) and to instead return to the OS command shell.
We could have instead used:
<syntaxhighlight lang="bash">$ :|jconsole -js "echo 'Hello'"
Hello
</syntaxhighlight>
for nearly identical behavior, but this issues J's command prompt before exiting. (But since J's command prompt is three space characters, this would be nearly invisible in many contexts, including here because the mediawiki implementation deletes those trailing spaces when rendering this page into html.)
=={{header|Java}}==
Line 408 ⟶ 436:
These three lines work with Bourne Shell (or compatible) or C Shell (or compatible), or bash on Unix/Linux/MacOSX/Windows+cygwin
<
> 'System.out.println("Hello Java!");}}' >X.java
$ javac X.java && java X</
A user can also enter this as one (very long) line:
<
{{works with|MS-DOS}} Compatible Environments (such as [[wp:cmd.exe|cmd.exe]])
Works with cmd.exe on Windows (tested on Microsoft Windows XP [Version 5.1.2600])
<
Hello Java!</
=={{header|JavaScript}}==
{{works with|SpiderMonkey}}
<
hello</
=={{header|jq}}==
<
2</
=={{header|Julia}}==
<
foo
bar</
=={{header|K}}==
{{works with|Kona}}
<
=={{header|Kotlin}}==
Line 448 ⟶ 476:
Hello Kotlin!
</pre>
=={{header|Lang}}==
This is an example for the Standard Lang implementation of Lang.
<syntaxhighlight lang="lang">
$ lang -e "fn.println(Hello World)"
</syntaxhighlight>
=={{header|langur}}==
=== Linux ===
<syntaxhighlight lang="langur">$ langur -e 'writeln "Are we reaching Fiji?"'
</syntaxhighlight>
=== Windows ===
<syntaxhighlight lang="langur">C:\> langur /e 'writeln "Are we reaching Fiji?"'
</syntaxhighlight>
{{out}}
<pre>Are we reaching Fiji?</pre>
=={{header|Lasso}}==
Line 453 ⟶ 499:
From stdin:
<
Or alternatively:
<
=={{header|Liberty BASIC}}==
<syntaxhighlight lang="lb">
echo print "hello">oneLiner.bas & liberty -r oneLiner.bas echo print "hello">oneLiner.bas & liberty -r oneLiner.bas
</syntaxhighlight>
=={{header|Lua}}==
<
=={{header|Maple}}==
<
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
=={{header|min}}==
<
=={{header|Nanoquery}}==
<
=={{header|NetLogo}}==
Line 483 ⟶ 529:
=== Observer Mode ===
<
=== Turtle Mode ===
<syntaxhighlight lang
=={{header|NetRexx}}==
{{works with|UNIX Shell}}
Create a temporary file, execute the file via the NetRexx interpreter then delete the temporary file and any files generated via the translation. (i.e. Java class files etc.)
<
$ TNRX=`mktemp T_XXXXXXXXXXXX` && test ! -e $TNRX.* && (echo 'say "Goodbye, World!"' >$TNRX; nrc -exec $TNRX; rm $TNRX $TNRX.*; unset TNRX)
</syntaxhighlight>
'''Output:'''
Line 507 ⟶ 553:
=={{header|NewLISP}}==
<
->"Hello"</
=={{header|Nim}}==
Line 527 ⟶ 573:
=={{header|Objeck}}==
{{works with|UNIX Shell}}
<
=={{header|OCaml}}==
<
Hello</
{{works with|OCaml|4.00+}}
<
Hello</
=={{header|Octave}}==
<
Hello World, it is 28-Aug-2013 17:53:47!</
=={{header|Oforth}}==
<
{{out}}
Line 550 ⟶ 596:
=={{header|ooRexx}}==
<
rexx -e "say 'Goodbye, world.'"
</syntaxhighlight>
=={{header|Oz}}==
This is difficult to do in Oz because the compiler/interpreter always wants the source code in a file and does not read from stdin. We can do somethings like this on Unix-like systems:
<
hello</
With <code>-l System</code> we make the System module available so that we can print something.
=={{header|PARI/GP}}==
<
=={{header|Pascal}}==
Line 568 ⟶ 614:
=={{header|Perl}}==
<
Hello</
More information about the many ways of invoking perl can be found in [http://perldoc.perl.org/perlrun.html perlrun].
Line 586 ⟶ 632:
=={{header|PHP}}==
assuming you have the PHP CLI (command-line interface) installed, not just the web server plugin
<
Hello</
=={{header|PicoLisp}}==
<
Hello world!</
=={{header|Pike}}==
<
Hello</
=={{header|PowerShell}}==
<
Hello</
=={{header|Processing}}==
Line 605 ⟶ 651:
In bash:
<
{{out}}
Line 614 ⟶ 660:
=={{header|Prolog}}==
===Command-Line Options===
<
hello world
$</
<
goodbye
$</
<
yap</
=== <<< ===
<
swi
$ yap -q <<< "current_prolog_flag(dialect,D), writeln(D), halt."
yap</
=== Pipe ===
<
swi
$ echo "current_prolog_flag(dialect,D), writeln(D), halt." | yap -q
yap</
=={{header|PureBasic}}==
Runs on Linux with(thanks to) bash. Path variables must be set as decribed in INSTALL.
<
=={{header|Python}}==
===Prints "Hello"===
<
Hello</
===Web server with CGI===
The python CGIHTTPServer module is also an [[Executable library|executable library]] that performs as a web server with CGI. to start enter:
<syntaxhighlight lang
It returns with:
<pre>Serving HTTP on 0.0.0.0 port 8000 ...</pre>
Line 652 ⟶ 698:
=={{header|Quackery}}==
<
hello</
===Via Python 3===
Line 659 ⟶ 705:
As Quackery is implemented as a Python 3 function, assuming that quackery.py is in the module search path:
<
hello</
=={{header|R}}==
<
Hello</
Alternatively, using the Rscript front-end,
<
Hello</
=={{header|Racket}}==
<
Hello World</
=={{header|Raku}}==
Line 678 ⟶ 724:
{{works with|Rakudo|#22 "Thousand Oaks"}}
<
Hello, world!</
=={{header|REBOL}}==
<
Output:
Line 688 ⟶ 734:
=={{header|Retro}}==
<
=={{header|REXX}}==
Note: Regina REXX is the only version of REXX that supports this type of behavior (taking it's input from a console stream).
<
╔══════════════════════════════════════════════╗
║ ║
Line 700 ⟶ 746:
echo do j=10 by 20 for 4; say right('hello',j); end | regina</
'''output''' when entering the (above) from the (DOS) command line:
<pre>
Line 710 ⟶ 756:
=={{header|Ring}}==
<
see "Hello World!" + nl
</syntaxhighlight>
Output:
<pre>
Hello World!
=={{header|RPL}}==
RPL command-line interpreter allows to pass several instructions and values in one line, provided there is no program branch instruction among them. It is nevertheless possible to have a program structure in the line by bracketing it with <code>≪ ≫</code>, which means "this is an unnamed program". Adding the word <code>EVAL</code> at the end will execute the code, otherwise it would stay at level 1 of the stack.
" World" "Hello" SWAP +
≪ " World" "Hello" SWAP + ≫ EVAL
This less trivial one-liner example calculates S(5), where S(n) is a Machin-like formula :
≪ 0 0 5 '''FOR''' k 2 k * 1 + → n ≪ -1 k ^ n / 4 5 n ^ / 239 n ^ INV - * + ≫ '''NEXT''' 4 * ≫ EVAL
{{out}}
<pre>
3: "Hello world"
2: "Hello world"
1: 3.14159265262
</pre>
=={{header|Ruby}}==
From [[Unix]]:
<
Hello</
{{works with|JRuby}}
<
Hello from JRuby</
{{works with|Rubinius}}
<
Hello from Rubinius</
=={{header|Run BASIC}}==
<
=={{header|Rust}}==
Line 738 ⟶ 798:
delete it to avoid to call another shell/system dependent command/program). The
''current directory'' is not specified by <tt>./</tt> in every system...
<
=={{header|S-lang}}==
<
Or, in MSW cmd.exe:
<
Note that print() is included w/slsh, but is not part of S-Lang itself.
Line 751 ⟶ 811:
=={{header|Scala}}==
{{libheader|Scala}}
<
Hello</
<
PS C:\> scala -e 'println(\"Hello\")'
Hello</
The escaping of quotes is required by Windows.
Line 763 ⟶ 823:
=={{header|Scheme}}==
{{works with|Guile}}
<
=={{header|sed}}==
The first non-option argument is interpreted as the script.
<syntaxhighlight lang="sh">$ sed q /proc/meminfo</syntaxhighlight>
Alternatively, scripts can be passed via the <code>-e</code> option.
<syntaxhighlight lang="sh">$ sed -e 's/[[:space:]]*$//' -e '/./!d' file.txt</syntaxhighlight>
=={{header|Shiny}}==
<
=={{header|Sidef}}==
<
=={{header|Slate}}==
<
=={{header|SNOBOL4}}==
Portable version
<
Bash version
<
=={{header|Tcl}}==
This is an area where Tcl is lacking, though when shell one-liners are required a construct like this is typically used:
<
Hello</
=={{header|TXR}}==
<
a="123"
b="456"
c="7890"
</syntaxhighlight>
Most useful txr queries consist of multiple lines, and the line structure is important. Multi-liners can be passed via <code>-c</code> easily, but there is no provision in the syntax that would allow multi-liners to be actually written as one physical line. There are opposite provisions for splitting long logical lines into multiple physical lines.
Line 799 ⟶ 865:
TXR Lisp:
<
4</
<
$ ls -ld foo
drwxrwxr-x 2 kaz kaz 4096 Mar 4 23:36 foo</
=={{header|UNIX Shell}}==
Explicit call of the shell, passing the shell command via the <code>-c</code> option:
<syntaxhighlight lang
<
To invoke a specific shell like [[Bash]], [[Korn Shell]] or [[Z Shell]]:
<
$ ksh -c 'let i=3+4; print $i'
$ zsh -c 'if [[ 5 -lt 6 ]] { echo ok };'</
Shell scripts almost never use <code>sh -c</code>, because there are various implicit ways whereby the shell command language evaluates a command in a subshell:
<
$ VAR=$(echo hello) # modern POSIX notation
$ (echo hello) # execute in another shell process, not in this one</
There are more details about <code>`echo hello`</code> and <code>$(echo hello)</code> at [[Execute a system command#UNIX Shell]].
Line 828 ⟶ 894:
Run a C shell command from any shell:
<
==={{header|es}}===
Run a command, in extensible shell, from any shell:
<
=={{header|Ursala}}==
The command to execute the Ursala compiler is fun. An expression supplied as a parameter to the --main option is compiled and evaluated. If the expression evaluates to a list of character strings, it can be displayed on standard output with --show. If it's some other type, it can be formatted for display by --cast <type expression>,
<
hello
$ fun --main="power/2 32" --cast %n
4294967296
$ fun --m="..mp2str mpfr..pi 120" --c %s
'3.1415926535897932384626433832795028847E+00'</
=={{header|Vedit macro language}}==
The following DOS command starts Vedit and displays a message.
When the user presses any key, Vedit exits.
<
=={{header|Wart}}==
<
=={{header|Wren}}==
<
{{out}}
Line 863 ⟶ 929:
=={{header|zkl}}==
With a unix like shell, just pipe the program into the REPL. Kinda greasy and noisy. To shut it up, send stdout to /dev/null
<
{{out}}
<pre>
|