单个bash文件中的多个shebang

Bar*_*jeu 8 bash shell-script shebang

我有一个来自其他人的脚本,可以查看(注意:它是一个文件):

#!/bin/bash

some commands
some commands

#!/bin/bash

some commands
some commands

#!/bin/bash

some commands
some commands
Run Code Online (Sandbox Code Playgroud)

我想知道第二次和第三次shebangs的目的是什么?是误会还是故意的?

dan*_*dan 10

如果这些行不是要构建的包含的 shell 脚本的开头,即在以下形式的方案中:

cat <<end_of_shell_script >dynamically_built_shell
#!/bin/bash
[...]
end_of_shell_script
Run Code Online (Sandbox Code Playgroud)

然后,你发现了重复的结构是很多人的结果copy-paste全shell脚本,但没有足够的照顾和什么是对脚本的第1行中使用这些非常特殊的评论的理解,开始#!

在使用这样的 shell 脚本之前要小心(不sudo,不su:))。

  • ... 或者组合多个 bash 脚本,类似于如果您按名称 `source` -d 它们的执行方式。不过,我不认为有必要发表评论。这种方式完全可以接受,这也是 shebang 是注释行的真正原因。 (3认同)