我在许多地方见过,包括这个网站上的建议( 什么是首选的Bash shebang? ),使用#!/usr/bin/env bash优先于#!/bin/bash 。 我甚至看到一个进取的个人建议使用#!/bin/bash是错误的,并且bash功能将会丢失。
所有这些说,我在一个严格控制的测试环境中使用bash,每个驱动器都是单个主驱动器的克隆。 我了解可移植性的论点,虽然这不一定适用于我的情况。 有没有其他理由喜欢#!/usr/bin/env bash替代方案,假设可移植性是一个问题,是否有任何理由使用它可能会破坏功能?
I've seen in a number of places, including recommendations on this site (What is the preferred Bash shebang?), to use #!/usr/bin/env bash in preference to #!/bin/bash. I've even seen one enterprising individual suggest using #!/bin/bash was wrong and bash functionality would be lost by doing so.
All that said, I use bash in a tightly controlled test environment where every drive in circulation is essentially a clone of a single master drive. I understand the portability argument, though it is not necessarily applicable in my case. Is there any other reason to prefer #!/usr/bin/env bashover the alternatives and, assuming portability was a concern, is there any reason using it could break functionality?
最满意答案
#!/usr/bin/env搜索bash PATH , bash并不总是在/bin ,特别是在非Linux系统上。 例如,在我的OpenBSD系统上,它在/usr/local/bin ,因为它被安装为可选的包。
如果你绝对确定bash在/bin并且永远是,直接将它放在你的shebang中没有任何危害 - 但是我建议反对它,因为脚本和程序都超出了我们最初相信他们会拥有的生活。
#!/usr/bin/env searches PATH for bash, and bash is not always in /bin, particularly on non-Linux systems. For example, on my OpenBSD system, it's in /usr/local/bin, since it was installed as an optional package.
If you are absolutely sure bash is in /bin and will always be, there's no harm in putting it directly in your shebang—but I'd recommend against it because scripts and programs all have lives beyond what we initially believe they will have.
更多推荐
发布评论