Multiline shebang
Simple shebangs can help with scripting, e.g. #!/usr/bin/env python at the top of a Python script will allow it to be run in a terminal as "./script.py".
Occasionally, a more complex shebang line is needed. For example, some languages do not include the program name in ARGV; a multiline shebang can reorder the arguments so that the program name is included in ARGV.
The syntax for a multiline shebang is complicated. The shebang lines must be simultaneously commented away from the main language and revealed to Bash so that they can be executed.
Chicken Scheme
- | ... |# provides just the right environment for the multiline shebang. Here, the script name is passed once to the Chicken Scheme Interpreter and once to be picked up in args.
<lang scheme>#!/bin/bash
- |
exec csi -ss $0 ${1+"$@"} exit |#</lang>
Clojure
The namespace = basename = filename minus the extension must be passed as a value to Clojure's -m flag.
<lang clojure>":";exec clj -m `basename $0 .clj` $0 ${1+"$@"} ":";exit</lang>
Common Lisp
Here, the script name is passed once to CLISP and once to ext:*args*, which normally omits it.
<lang lisp>#!/bin/bash
- |
exec clisp -q -q $0 $0 ${1+"$@"} exit |#</lang>
Emacs Lisp
<lang lisp>:;exec emacs -batch -l $0 -f main $*</lang>
Erlang
Note that the binary is escript, not erl. The latter refuses to compile or run code that contains a shebang.
<lang erlang>#!/usr/bin/env escript</lang>
Haskell
A plain shebang will do.
<lang haskell>#!/usr/bin/env runhaskell</lang>
Lua
A plain shebang will do.
<lang lua>#!/usr/bin/env lua</lang>
newLISP
A plain shebang will do.
<lang lisp>#!/usr/bin/env newlisp</lang>
Node.js
A plain shebang will do.
<lang javascript>#!/usr/bin/env node</lang>
Perl
A plain shebang will do.
<lang perl>#!/usr/bin/env perl</lang>
Python
A plain shebang will do.
<lang python>#!/usr/bin/env python</lang>
R
Note that the binary is Rscript, not the R interpreter. Regardless, scripts must end with q("no") in order to terminate and return to the shell.
<lang R>#!/usr/bin/env Rscript</lang>
Ruby
A plain shebang will do.
<lang ruby>#!/usr/bin/env ruby</lang>
Smalltalk
<lang smalltalk>"exec" "gst" "-f" "$0" "$0" "$@" "exit"</lang>
Tcl
Note that the binary is tclsh.
<lang tcl>#!/usr/bin/env tclsh</lang>
- Draft Programming Tasks
- Basic language learning
- Chicken Scheme
- Clojure
- Common Lisp
- Emacs Lisp
- Erlang
- Erlang examples needing attention
- Examples needing attention
- Haskell
- Haskell examples needing attention
- Lua
- Lua examples needing attention
- NewLISP
- NewLISP examples needing attention
- Node.js
- Node.js examples needing attention
- Perl
- Perl examples needing attention
- Python
- Python examples needing attention
- R
- R examples needing attention
- Ruby
- Ruby examples needing attention
- Smalltalk
- Tcl
- Tcl examples needing attention