Currently, in terminal, my default interactive shell is bash version 4.4. The OS ships with 3.2.
If I want to run a script (e.g., my_script.sh
) using bash version 4.4, I can source it (source my_script.sh
) or type it into my terminal directly. Though, in each case the script runs in my current shell. I can also give a script execute permissions and run it as a command, allowing the shebang to control which version of bash to use.
However, the command bash
continues to use version 3.2. For example, if I run bash my_script.sh
, the script will be executed in a new shell (which I want), but the older version of bash will be used (3.2). Similarly, if I just run bash
with no argument, a new shell opens up using version 3.2 (recall, if I open a new window or tab in terminal, it uses my default shell, bash v. 4.4. The problem here is what happens when I use the command bash
).
I've added the path to bash 4.4 on my machine (/usr/local/bin/bash
) to my PATH
variable in .bash_profile
, and it's not being overwritten somewhere else (echo $PATH
gives the expected result: the very first path is usr/local/bin/bash
). I expected this to change the behavior of the command bash
I can use a workaround, by setting an alias (alias bash4='/usr/local/bin/bash'
), but I don't have to use an alias for bash 3.2, or for upgraded versions of, e.g., python or R.
Is there something I'm missing? Is the alias solution the only option here?
EDITS
in response to comments:
SHELL
is /usr/local/bin/bash
, which is unsurprising, since that's my default login shell.
type -a bash
is interesting...
bash is /bin/bash
bash is /usr/local/bin/bash
bash is /bin/bash
bash is /usr/local/bin/bash
bash is /bin/bash
bash is /usr/local/bin/bash
bash is /bin/bash
bash is /usr/local/bin/bash
My entire PATH is a mess, which may be the source of this problem.
/usr/local/bin/bash:/Users/coltrane/Programming/Unix_Workbench/Code/Commands:/usr/local/bin/bash:/Users/coltrane/Programming/Unix_Workbench/Code/Commands:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Library/TeX/texbin:/opt/X11/bin:/usr/local/git/bin:/Applications/anaconda/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/Users/coltrane/Programming/Unix_Workbench/Code/Commands:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Library/TeX/texbin:/opt/X11/bin:/usr/local/git/bin:/Applications/anaconda/bin:/Users/coltrane/Programming/Android_Development/sdk/platform-tools:/Library/Frameworks/R.framework/Resources/bin:/usr/local/git/bin:/Applications/anaconda/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/Users/coltrane/Programming/Unix_Workbench/Code/Commands:/usr/local/bin/bash:/Users/coltrane/Programming/Unix_Workbench/Code/Commands:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Library/TeX/texbin:/opt/X11/bin:/usr/local/git/bin:/Applications/anaconda/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/Users/coltrane/Programming/Unix_Workbench/Code/Commands:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Library/TeX/texbin:/opt/X11/bin:/usr/local/git/bin:/Applications/anaconda/bin:/Users/coltrane/Programming/Android_Development/sdk/platform-tools:/Library/Frameworks/R.framework/Resources/bin:/usr/local/git/bin:/Applications/anaconda/bin:/Users/coltrane/Programming/Android_Development/sdk/platform-tools:/Library/Frameworks/R.framework/Resources/bin
unrelated problem with my path, i had inadvertently repeated $PATH
in one line of my .bash_profile
, (PATH=$PATH::$PATH) causing unwanted duplication
type -a bash
andecho $SHELL
.echo $PATH
. The default bash is found in/bin/bash
and I'm betting it comes before the path to bash v.4./bin
. Confirm this by typingwhich bash
. But we still need to see your path./bin
is in there multiple times, and I understood it should stay there. I put the path to bash 4.4 at the very beginning to solve this, though.