Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是Shebang #!吗,例如
#!
#!/bin/sh
在 Linux 标准库或任何 The Open Group 标准或其他地方正式标准化的脚本可执行文件之前?如果是,请提供参考资料和详细信息。
注意:我最感兴趣的是它对 shell 脚本以及任何可执行文件的含义。换句话说,是否有任何标准要求#!在可执行文件的开头进行类似 shebang 的解释?但是,也欢迎在标准中对其进行任何其他引用。
POSIX留下#!未指定的效果。从2.1 外壳介绍
shell 从文件(参见 sh)、-c 选项或 POSIX.1-2008 的系统接口卷中定义的 system() 和 popen() 函数读取其输入。如果 shell 命令文件的第一行以字符“#!”开头,则结果未指定。
从来源:
Bash 脚本通常以 #! /bin/bash(假设 Bash 已安装在 /bin 中),因为这确保了 Bash 将用于解释脚本,即使它是在另一个 shell 下执行的。
你也可以检查这个#! 魔术,关于各种 Unix 风格的 shebang/hash-bang 机制的详细信息