I am using Big Sur for work. I want to write a bash script that uses some modern bash features.
The bash that comes with Big Sur is fairly old:
$ /bin/bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin20)
So in I installed a later version with brew:
$ /usr/local/bin/bash --version
GNU bash, version 5.1.8(1)-release (x86_64-apple-darwin20.3.0)
This version has the features I want. However, I want the script to be cross-platform, so hardcoding this path at the beginning of scripts causes it not to work on our cloud environment, and certain other devs' machines:
#!/usr/local/bin/bash
From researching, I've found that a standard way to make a script cross-platform is to use this to get a bash location:
#!/usr/bin/env bash
Which lets the user define a location for bash. However, I have not been able to get the command working on my local environment!
This command returns nothing-- I'm expecting it should return the full path to a bash. It doesn't even return the path to the default system bash.
$ /usr/bin/env bash
I've added /usr/local/bin/bash
to my .profile
, but that hasn't seemed to work.
$ cat .profile
export PATH="/usr/local/sbin:/usr/local/bin/bash:$PATH"
How do I configure my environment, shell, or whatever so that /usr/bin/env
gives the path to /usr/local/bin/bash
?
I'm using Big Sur 11.6.4 using Terminal 2.11.
env
picks up the wrongbash
(e.g. if a user redefined their PATH).