Hi I'm trying to update bash in my shell scripts to v5 on macos. Example shell scripts:

#!/usr/bin/env bash
which bash

Updating bash in my terminal is successfull however in any of my existing shell scripts, it keeps on falling back to v3.2.57(1)-release (/bin/bash) wile i want to use v5.x (which is in /usr/local/bin/bash). Whenever I change the PATH variable so that /bin/ is not included (only /bin/env) I get a different error:

env: bash: No such file or directory

Whenever I do include it, v3.2 is used in the script..

Things I did:

  • Removed /bin/bash from /etc/shells
  • Tried change PATH variable so that #!/usr/bin/env bash still works but v3.2 is not used
  • Add /usr/local/bin to path which results in./my-script: line 215: sh: command not found

Anyone has any more tips I can try?

My Path configuration:

#start path from fresh
export PATH=/usr/local/bin
export PATH=$PATH:/bin
export PATH=$PATH:/usr/bin/
echo $PATH #output = /usr/local/bin:/bin:/usr/bin/
  • 2
    Don't add env or 'bash' to PATH -- they are commands, not paths. Don't exclude /bin from PATH. Add /usr/local/bin to the front end of PATH, so it gets called first.
    – benwiggy
    Commented Dec 9, 2022 at 17:47
  • @benwiggy Thanks, I've changed the config but I still have the same error. Wil update my begin post
    – Vincent
    Commented Dec 11, 2022 at 12:27
  • If you do which bash on the Terminal prompt, what do you get?
    – benwiggy
    Commented Dec 11, 2022 at 12:49
  • /usr/local/bin/bash. And when I execute the version it's the one I want. /usr/local/bin/bash --version GNU bash, version 5.2.12(1)-release (x86_64-apple-darwin21.6.0)
    – Vincent
    Commented Dec 11, 2022 at 12:53
  • 1
    Please create a script which only includes the three lines you list at the top of your post, and add a echo $PATH as a forth line; and then run it with both the ways I described. Afterwards add the result to the question with an edit, too much gets lost in comments.
    – nohillside
    Commented Dec 12, 2022 at 8:17

1 Answer 1


After correcting my path config as was suggested in the comments. I found out the bash version in the script was actually set correctly in the original script but not in the script that followed after that. So the problem was script A was calling script B by doing

sh next-script-to-run.sh params #runs in v3

After changing this to run the script without the sh command. All scripts ran in bash v5:

./next-script-to-run.sh params #runs in v5

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .