为什么#!的/ usr / bin中/ env的庆典优于#!/斌/ bash的? [英] Why is #!/usr/bin/env bash superior to #!/bin/bash?

查看:85
本文介绍了为什么#!的/ usr / bin中/ env的庆典优于#!/斌/ bash的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过许多地方,包括在本网站的建议( preferred bash的家当?),使用#!的/ usr / bin中/ env的庆典在preference到#!/ bin中/庆典。我甚至见过一个进取的个人(mywiki.wooledge.org/BashGuide/Practices,他的网站似乎是在下降的时刻)建议使用#!/斌/庆典是的错误的和bash的功能将由这样失去了。

I've seen in a number of places, including recommendations on this site (Preferred bash shebang?), to use #!/usr/bin/env bash in preference to #!/bin/bash. I've even seen one enterprising individual (mywiki.wooledge.org/BashGuide/Practices, his site seems to be down at the moment) suggest using #!/bin/bash was wrong and bash functionality would be lost by doing so.

所有这一切说,我使用bash在一个严格控制的测试环境中,在流通的每个驱动器基本上是一个单一的主驱动器的克隆。我理解的便携性的说法,虽然它并不一定适用于我的情况。是否有任何其他理由preFER #!的/ usr / bin中/ env的庆典在替代品,假定便携性是一个问题,有没有使用它可以在任何原因打破功能?

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的搜索 PATH 庆典庆典并不总是 / bin中,特别是对非Linux系统。例如,在我的OpenBSD系统上,它在的/ usr / local / bin目录,因为它是作为选件安装包。

#!/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.

如果你是绝对肯定庆典 / bin中而且将永远是,有一个在把它没有害处直接在你的家当,但我建议反对,因为脚本和程序都超出了我们最初认为他们将不得不生活。

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.

这篇关于为什么#!的/ usr / bin中/ env的庆典优于#!/斌/ bash的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆