I have homebrew\'s bash package installed. When I open a new shell:
bash --version
gives GNU bash, version 5.0.7(1)-release (x86_64-apple-darwin18
The source of my problem was a terminal app preference setting. The "Command (complete path)" was set to /bin/bash
. After setting it to "Default login shell", echo $BASH_VERSION
reported the version I expected. The other problem is I stupidly ran the bash --version
command in iTerm2, not terminal. So it gave a different response than what terminal would have.
It means that the shell you're in is Bash 3.2, but bash
points to Bash 5.0. Try bash
and then, in the new shell, echo $BASH_VERSION
– I guess it'll be 5.0. To change your login shell, add /usr/local/bin/bash
to /etc/shells
and change the default shell with
chsh -s /usr/local/bin/bash
sudo chsh -s /usr/local/bin/bash
After logging out and in again, $BASH_VERSION
should be updated.
As for shebang lines, I recommend
#!/usr/bin/env bash
as it's portable and will use the first Bash in your $PATH
.
Your login shell (see echo $SHELL
) is probably /bin/bash
and that is the one setting $BASH_VERSION
. If you need to use a specific version in scripts, use the full path in the #!
line.