Common Lisp has multiline shebangs:
#!/bin/bash
#|
exec clisp -q -q $0 $0 ${1+"$@"}
exit
|#
This allows more complex operations within a shebang. CLISP is one of the few languages that omits the script name from ARGV. Here, the script name is forcibly sent twice to CLISP so that the Lisp script can access its script name via ARGV.
Is there a way to do this in Factor so that the following works?
$ cat ios7crypt.factor
#! /usr/bin/env factor
USING: kernel namespaces io prettyprint ;
IN: ios7crypt
: usage ( -- )
"Usage: ios7crypt.factor [options]" print
"-encrypt <password>" print
"-decrypt <hash>" print
"-test" print
"-help" print ;
: main ( -- ) "help" get . ;
MAIN: main
$ ./ios7crypt.factor
f
$ ./ios7crypt.factor -help
f
The above line should print t
, but Factor ignores -help
because it came after the script name.
$ factor ios7crypt.factor
f
$ factor -help ios7crypt.factor
t
This works because -help
was sent before the script name. ./ios7crypt.factor -help
silently drops -help
because the shebang expands to factor ios7crypt.factor -help
. Unfortunately, Factor seems to require all command line options before the script name.
Is there a multiline shebang overriding this behavior?
Command line options sent to a script are not automatically parsed. One must manually send them to the parser.
$ cat args.factor
#! /usr/bin/env factor
USING: namespaces command-line prettyprint ;
IN: args
: main ( -- )
command-line get parse-command-line
"a" get .
"b" get .
"c" get .
;
MAIN: main
Example:
$ ./args.factor -a -b=banana
t
"banana"
f