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
.
Best Answer
I used homebrew to install BASH4 and I use the shebang
#!/bin/bash
every time. This works for me with both sh and ./ styles of running.