Multiline shebang: Difference between revisions
Content added Content deleted
(→{{header|Nim}}: Rescued OCaml entry which had become tangled up with Nim.) |
(Added Wren) |
||
Line 708: | Line 708: | ||
arg[3]="3" |
arg[3]="3" |
||
$</pre> |
$</pre> |
||
=={{header|Wren}}== |
|||
Wren doesn't support multiline shebangs as such. Anything after the first line is always interpreted as Wren code. |
|||
You can get around this by placing shell commands in a block comment after a single line shebang. So (ignoring the strange error message) the following works: |
|||
<lang ecmascript>#!/bin/bash |
|||
/* |
|||
echo "Hello from bash" |
|||
/bin/wren multiline_shebang.wren |
|||
exit |
|||
*/ |
|||
System.print("Hello from Wren")</lang> |
|||
{{out}} |
|||
<pre> |
|||
$ chmod +x multiline_shebang.wren |
|||
$ ./multiline_shebang.wren |
|||
./multiline_shebang.wren: line 2: /bin: Is a directory |
|||
Hello from bash |
|||
Hello from Wren |
|||
</pre> |
|||
<br> |
|||
However, we don't actually need a multiline shebang to get the script name as this is always passed automatically as the second command line argument when the Wren process is spawned, the first argument being the Wren executable itself. Moreover, if a single line shebang is used, the third argument will be the shell command used to execute the script. |
|||
<lang ecmascript>#!/bin/wren multiline_shebang.wren |
|||
import "os" for Process |
|||
var args = Process.allArguments |
|||
System.print("Executable : %(args[0])") |
|||
System.print("Script name : %(args[1])") |
|||
System.print("Shell command : %(args[2])") |
|||
if (args.count > 3) { |
|||
for (i in 3...args.count) System.print("Argument %(i-2) : %(args[i])") |
|||
}</lang> |
|||
{{out}} |
|||
<pre> |
|||
$ ./multiline_shebang.wren |
|||
Executable : /bin/wren |
|||
Script name : multiline_shebang.wren |
|||
Shell command : ./multiline_shebang.wren |
|||
Argument 1 : one |
|||
Argument 2 : two |
|||
Argument 3 : three |
|||
</pre> |
|||
=={{header|zkl}}== |
=={{header|zkl}}== |