Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$BASH_VERSION reports old version of bash on macOS, is this a problem that should be fixed?

Tags:

bash

macos

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.5.0)

which bash gives /usr/local/bin/bash as expected.

But:

echo $BASH_VERSION yields 3.2.57(1)-release

I'm wondering if this is something I should address for scripts that might use this environment variable.

like image 370
StevieD Avatar asked May 13 '19 18:05

StevieD


People also ask

Why is Mac Bash so old?

The reason that Apple includes such an old version of Bash in its operating system has to do with licensing. Since version 4.0 (successor of 3.2), Bash uses the GNU General Public License v3 (GPLv3), which Apple does not (want to) support.

Is Bash on Mac?

For a long time, the bash was a default shell in macOS. However, Apple replaced Bourne Again SHell with Z shell for licensing reasons.


1 Answers

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.

like image 134
Benjamin W. Avatar answered Sep 27 '22 22:09

Benjamin W.