It is a question related to this other one, but I can't comment.

I've updated to use bash 4 from brew installation. But I don't know if changing all the header scripts from:




Isn't a portable solution.

Moreover, some scripts check if the shell is a /bin/bash shell (docker-toolbox in example)

Before writing, I was recommended to read this: But the path solution is neither portable nor can apply on docker case (no direct source).

So I still doubt: is really a bad idea to softlink the bash?

Obviously, targeting independent-version.

  • 1
    Upgrading the OS could overwrite it - why update bash for these scripts - I can understand for terminal sessions - what improvement do you get -the scripts are probably written for older bash anyway – Mark Sep 25 '15 at 16:08
  • Upgrading: ok, it is true, so maybe someday I'll find myself in bash 3 without knowing ^^' ---- Scripts: when I write scripts, as I write code, I try to use latest software available, but most portable possible too. If I share my script with others and the bash line is not the /bin/bash, will complain anything? – lucasvc Sep 26 '15 at 11:32
  • 1
    It depends of the other person has an interpreter at the path you give - if not then it will not run - if they do hope it is the correct version - note if I have to write a shell script I will write it as sh as that will be portable, if more complex I'll use python, perl etc – Mark Sep 26 '15 at 13:20
  • Really nice comments! You have convinced me. Could you put them as answer? – lucasvc Sep 26 '15 at 15:21
  • With SIP (the "rootless" feature of 10.11), the problem kind of solves itself as you are no longer able to modify /bin. – nohillside Oct 2 '15 at 9:02

#!/usr/bin/env bash is the 'most portable' approach but #!/bin/bash is the standard convention on OS X and Linux. There are advantages to shebang with a stable system interpreter, and it's probably not worth using a newer Bash.

  • Is bash 4 less stable than 3? It is still updated version 3? – lucasvc Oct 2 '15 at 9:13
  • By stable I mean it's not likely to flip through versions, will survive OS upgrades and changes. You can still use Bash 4 as a shell but if your script doesn't use Bash 4 features I'd just stick with /bin/bash. – Ian Oct 2 '15 at 9:27

Create your own bash symbolic link. Then use that in your script. You can then change the symlink to point to whatever you want. That's the approach used with java-alternatives and other platforms (ruby, python, etc.). Thus, they change the symlinks, and you have a new version in your environment.

  • Yes, I know how, my question was about good or bad idea in the bash case. Thanks anyway. – lucasvc Sep 26 '15 at 11:26

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.