Multiline shebang: Difference between revisions
(Added Emacs Lisp) |
No edit summary |
||
Line 23: | Line 23: | ||
=={{header|Emacs Lisp}}== |
=={{header|Emacs Lisp}}== |
||
<lang lisp>:;exec emacs -batch -l $0 -f main $*</lang> |
<lang lisp>:;exec emacs -batch -l $0 -f main $*</lang> |
||
=={{header|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> |
Revision as of 05:22, 6 August 2011
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. You need to simultaneously comment the shebangs away from the language and reveal them uncommented to Bash so that the shebangs can be executed.
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>