I am trying to create shell scripts that make use of Bash 4.0's features. I am on a Mac using zshell as my main shell, and I have bash 4.0 installed via Homebrew.
When I run bash --version from iTerm, I get:
GNU bash, version 4.4.23(1)-release (x86_64-apple-darwin17.5.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.
But if I try to execute echo "Using $BASH_VERSION" from within my script, I get: Using version 3.2.57(1)-release
How do I get my virtual shell for my scripts to point to Bash 4.0?
Your shell script should start with the line:
Which should point to the installed bash you want. Since you seem to be contend with the bash that was found by executing
bash --version, you can executewhich bashto tell you where that one is.Alternately, you can start your script with:
Which will use the bash that is found on your PATH.