google / styleguide

Style guides for Google-originated open-source projects

Home Page:https://google.github.io/styleguide/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Shell] Shebang `#!/bin/bash` vs. `#!/usr/bin/env bash`

kawofong opened this issue · comments

Hi friends,

On the Shell Style Guide, there is strong language around how bash shebangs should be implemented: "Executables must start with #!/bin/bash..."

However, from past experience and research online, a lot of developers in the community has suggested that #!/usr/bin/env bash is a better shebang for portability reasons. Here are just a few of those resources:

Ask: Can someone help me understand why the shell style guide recommends such strongly on #!/bin/bash vs. #!/usr/bin/env bash? In my opinion, it will be better to recommend different options of shebangs and highlight their tradeoffs in the style guide instead.

Shell scripts at Google (and most companies) tend to be targeting a specific environment. Portability to BSD, Solaris, Mac etc are usually not a concern. So long as you are planning on sticking to GNU Linux, /bin/bash tends to work and is more straight forward (and supports passing flags on the shebang line).

If you are concerned about portability, the guidance about shebangs here may not be right for you.