相关疑难解决方法(0)

Why does this snippet with a shebang #!/bin/sh and exec python inside 4 single quotes work?

I'm trying to understand one of the answers to this question:

Cannot pass an argument to python with "#!/usr/bin/env python"

#!/bin/sh
''''exec python -u -- "$0" ${1+"$@"} # '''
Run Code Online (Sandbox Code Playgroud)

This works well, but I do not understand why it works with four ticks at the beginning of that line rather than three.

In addition, why the hash near the end of that string?

python bash arguments shebang sh

15
推荐指数
1
解决办法
2878
查看次数

有条件的shebang行为不同版本的Python

尝试在两台不同的计算机上运行python脚本时遇到问题.在每台计算机上,我想使用python版本2.7.3运行脚本,但我遇到的问题是两台计算机以不同的方式命名python 2.7.3.其中一台计算机运行arch linux,在这台计算机上运行它名为python2.另一台计算机正在运行redhat linux,它使用名称python2.7.3.

我应该在shebang行中使用什么,以便脚本可以在两台计算机上执行而无需任何更改?我真正想要的是某种有条件的shebang系列,它可以选择使用哪个版本的Python.我只是运气不好,我必须保留两个不同版本的脚本?

PS我不能只使用#!/ usr/bin/env python在arch linux计算机上这将引用python 3.2.3,在redhat linux计算机上它将引用python 2.4.

python conditional shebang

14
推荐指数
2
解决办法
2054
查看次数

标签 统计

python ×2

shebang ×2

arguments ×1

bash ×1

conditional ×1

sh ×1