Factor 是否有多行 shebang?
Common Lisp 具有多行 shebang:
#!/bin/bash
#|
exec clisp -q -q $0 $0 ${1+"$@"}
exit
|#
这允许在 shebang 内进行更复杂的操作。 CLISP 是少数从 ARGV 中省略脚本名称的语言之一。这里,脚本名称被强制发送两次到 CLISP,以便 Lisp 脚本可以通过 ARGV 访问其脚本名称。
有没有办法在 Factor 中做到这一点,以便以下工作有效?
$ 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
上面的行应该打印 t
,但 Factor 会忽略 -help
,因为它位于脚本名称之后。
$ factor ios7crypt.factor
f
$ factor -help ios7crypt.factor
t
这是有效的,因为 -help
是在脚本名称之前发送的。 ./ios7crypt.factor -help
默默地删除 -help
,因为 shebang 扩展为 factor ios7crypt.factor -help
。不幸的是,Factor 似乎需要脚本名称之前的所有命令行选项。
是否有多行 shebang 覆盖此行为?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发送到脚本的命令行选项不会自动解析。必须手动将它们发送到解析器。
例子:
Command line options sent to a script are not automatically parsed. One must manually send them to the parser.
Example: