I have installed bash 4 with Homebrew and bash --version shows me the version 4.
If I have following test script:
#!/usr/local/bin/bash
# test-version.sh
echo $BASH_VERSION
And I make it executable chmod +x configurer.sh and run it ./test-version.sh I also get the version 4.
But if I run it with the sh command sh test-version.sh I get the version 3.
I have put the new shell into /etc/shells:
sudo bash -c 'echo /usr/local/bin/bash >> /etc/shells'
And changed to the new shell:
chsh -s /usr/local/bin/bash
I also changed the path in iTerm Settings > Profiles > Command to /usr/local/bin/bash.
Thanks!
EDIT: I've come to realize that it's good to leave sh alone. When wanting to run scripts with Bash 4 just don't use sh.
echo $PATH? – airsquared Oct 25 '18 at 16:58/bin/shis a shell that will correctly execute a script written against the POSIX specification. It does not guarantee any particular behavior on a script using non-POSIX extensions. – chepner Sep 14 '20 at 19:05