Shebang在文件标头中的使用:是否有任何选择在Shebang中通过多个参数
我正在使用其他名称空间进行我的python文件执行。使用Shebang/Hashbang执行此脚本(/bin/bash -c)。
面临的问题是Shebang仅接受一个论点。即使我传递了多个ARG,它也将其视为一个字符串。
Shebang使用了: #!/sbin/ip netns exec exec tmp< oputable>
实验:
单个可执行文件使用:
#!/sbin/ip
对象“ TMP”未知,请尝试“ IP帮助”。
tmp中的一个arg shebang:
#!/sbin/ip netns
$/bin/bash -c tmp 命令“ TMP”是未知的,请尝试“ IP Netns帮助”。
tmp中使用的两个arg shebang:
#!/sbin/ip netns exec
$/bin/bash -c tmp 对象“ netns exec”未知,请尝试“ IP帮助”。
- 其选择“ Netns Exec”作为单个参数
完整的cmd使用
shebang在TMP中使用:
#!/sbin/ip netns exec exec global python
$/bin/bash -c tmp 对象“ Netns Exec Global Python”是未知的,请尝试“ IP帮助”。
是否有任何方法可以将多个Argumenets传递给Shebang可执行文件以外的其他方法。
I am using a different namespace for my python file execution. using a shebang/hashbang, to execute this script (/bin/bash -c ).
problem faced is shebang only accepts a single argument. even if i pass multiple args its treating it as a single string.
shebang used:#!/sbin/ip netns exec tmp <executable>
Experiment:
single executable using :
#!/sbin/ip
Object " tmp" is unknown, try "ip help".
one arg shebang in tmp :
#!/sbin/ip netns
$/bin/bash -c tmp Command "tmp" is unknown, try "ip netns help".
with two arg shebang used in tmp:
#!/sbin/ip netns exec
$/bin/bash -c tmp Object "netns exec" is unknown, try "ip help".
- its picking "netns exec" as a single argument
full cmd used
shebang used in tmp :
#!/sbin/ip netns exec global python
$/bin/bash -c tmp Object "netns exec global python" is unknown, try "ip help".
Is there any way to pass multiple argumenets to shebang executable other than chaining files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Linux(我相信其他OSS)在第一个空格时只分开了一次Shebang String。因此,您只能通过一个论点。
当您执行
#!/sbin/ip Netns Exec exec tmp&lt; ostable&gt;
,ip
看到一个参数字符串:netns exec exec exec tmp&lt; dostable&gt;
(包括空间)。但是gnu
env
添加了用于拆分Shebang参数的-s
选项。它也可以在FreeBSDenv
上使用。但不是busyboxenv
。因此,如果您使用
env -s
:env> env
将它们在空白空间上拆分三个参数,然后将它们传递给命令
。env
当然正在看到单个参数-s命令-a -b -c
,但可以解析此。我对名称空间的了解不足以知道这是否是个好主意,但它似乎对我有用:
我显示出bash,但它也适用于类似的python脚本。我将重复一遍,我对名称空间不了解,无法知道这是否是一种很好的方法。
Linux (and other OSs I believe) only split the shebang string once, at the first whitespace. So you can only ever pass one argument.
When you do
#!/sbin/ip netns exec tmp <executable>
,ip
sees one argument string:netns exec tmp <executable>
(including spaces).But GNU
env
added the-S
option for splitting shebang arguments. It's also available on FreeBSDenv
. But not busyboxenv
.So if you launch your interpreter using
env -S
:env
will split the three arguments on white space, and pass them tocommand
.env
of course is seeing the single argument-S command -a -b -c
, but it can parse this.I don't know enough about namespaces to know if this is a good idea, but it seemed to work for me:
I'm showing bash, but it also worked with a similar python script. I will repeat that I don't know enough about namespaces to know if this is a good approach or not.