1

I tried copying from /usr/local/Cellar/bash/4.4.19/bin/bash to /usr/local/bin/bash because which bash shows /usr/local/bin/bash.

~/cat /etc/shells
/usr/local/Cellar/bash/4.4.19/bin/bash

~/bash --version
GNU bash, version 4.4.19(1)-release (x86_64-apple-darwin17.3.0)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.


echo $BASH_VERSINFO
3

How do I fix this?

codeforester
  • 39,467
  • 16
  • 112
  • 140
quantumpotato
  • 9,637
  • 14
  • 70
  • 146
  • 1
    `bash --version` starts a new copy of bash; it doesn't tell you the version of the shell you're *currently running*, but instead tells you the version of *the one that's first in the PATH*. – Charles Duffy Apr 25 '18 at 18:01
  • I tried PATH=/usr/local/Cellar/bash/4.4.19/bin/bash:$PATH in my ~/.bash_profile , there is no other reference to a bash binary there – quantumpotato Apr 25 '18 at 18:04
  • Your `.bash_profile` is too late; by definition, it's only run *after* a bash executable is started. BTW, you can't put an executable name in your PATH -- only directories are honored. – Charles Duffy Apr 25 '18 at 18:05
  • If you want to change the shell your user account is configured to use, that's what `chsh` is for. – Charles Duffy Apr 25 '18 at 18:06
  • See comments in [bash on Mac does not have associative arrays even on version 4](https://stackoverflow.com/questions/46963899/bash-on-mac-does-not-have-associative-arrays-a-even-on-version-4). – Charles Duffy Apr 25 '18 at 18:06
  • @CharlesDuffy I was able to change shell, thank you. Still getting caught by a script^ see edit, that checks for BASH_VERSINFO < 4 – quantumpotato Apr 25 '18 at 18:09
  • Frankly, that script is badly written -- it'll fail with a syntax error on shells that aren't bash at all rather than doing so gracefully. `case $BASH_VERSION in ''|[0-3].*) echo "This script requires bash version 4 or above." >&2; exit 1;; esac` is much more reliable, as it will fail gracefully in the intended way on *any* POSIX-compliant shell other than bash 4.0 or newer. – Charles Duffy Apr 25 '18 at 18:10
  • BTW, what's the shebang on the script? If it uses `#!/bin/bash`, change it to `#!/usr/bin/env bash`. That's a problem you don't even need `chsh` to fix. – Charles Duffy Apr 25 '18 at 18:11
  • Ah, fixing the shebang fixed the error, thank you. – quantumpotato Apr 25 '18 at 18:24
  • It's probably worth editing the question to ask about only one question -- right now it's got the first section asking about interactive shell selection, and the second section asking about a script's shell selection (but not, right now, containing enough information to debug same -- the shebang being key/essential/unavoidable for that). Those are quite different matters; we might not have a duplicate for the former, but I'd be surprised if we didn't have one for the latter. Either way, once it's resolved down to one specific question it can either get an answer or be closed as a duplicate. – Charles Duffy Apr 25 '18 at 18:26
  • Done @ Charles Duffy – quantumpotato Apr 27 '18 at 18:54

1 Answers1

6

bash --version shows the version that would be run if a new shell were started from the PATH.

Thus, this version correlates with the install location from which bash (if not modified by aliases/functions/etc), or type bash (more accurately), or with the shell used to run a script with a #!/usr/bin/env bash shebang.


$BASH_VERSINFO and $BASH_VERSION show the version that's running right now.

Thus, if you're in a script with a #!/bin/bash shebang, or an interactive shell script for a user whose password database specifies /bin/bash as their shell, /usr/local/bin/bash (or any other location) being earlier in the PATH is irrelevant for purposes of the current, not-started-from-the-PATH shell instance.


To start the shell from the PATH in a script, change your shebang to #!/usr/bin/env bash. To start a specified shell from an interactive session, use chsh to update your account's settings.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441