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

后端 未结 3 611
闹比i
闹比i 2020-12-03 23:04

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

相关标签:
3条回答
  • 2020-12-03 23:52

    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.

    0 讨论(0)
  • 2020-12-03 23:58

    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.

    0 讨论(0)
  • 2020-12-04 00:00

    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.

    0 讨论(0)
提交回复
热议问题