Skip to main content
added 243 characters in body
Source Link
Alexander Mills
  • 10.9k
  • 27
  • 120
  • 214

I am trying to setup a system to switch between bash versions on a Mac. I have this which works:

change_bash_version(){ if test "$1" == "3"; then export PATH="$HOME/bash/versions/3.2.57:${PATH}" elif test "$1" == "4"; then export PATH="$HOME/bash/versions/4.4.18:${PATH}" else export PATH="$HOME/bash/versions/5.0:${PATH}" fi } export -f change_bash_version 

I tried using aliases but they are not inherited - my question is - is there an alternative to changing the PATH to putting the desired bash executable in front? It doesn't work very easily to put an entire directory on the PATH if that dir has a bunch of extraneous files that I don't want the PATH to see.

The other downside to this technique is having to use a bash function to switch versions (unless someone can think of way to use a command line utility).

I tried using this:

change_bash_version(){ bash(){ $HOME/bash/versions/4.4.18/bash "$@" } export -f bash; # error here } 

but bash did not like that - saying "bash" is not a function

I am trying to setup a system to switch between bash versions on a Mac. I have this which works:

change_bash_version(){ if test "$1" == "3"; then export PATH="$HOME/bash/versions/3.2.57:${PATH}" elif test "$1" == "4"; then export PATH="$HOME/bash/versions/4.4.18:${PATH}" else export PATH="$HOME/bash/versions/5.0:${PATH}" fi } export -f change_bash_version 

I tried using aliases but they are not inherited - my question is - is there an alternative to changing the PATH to putting the desired bash executable in front? It doesn't work very easily to put an entire directory on the PATH if that dir has a bunch of extraneous files that I don't want the PATH to see.

The other downside to this technique is having to use a bash function to switch versions (unless someone can think of way to use a command line utility).

I am trying to setup a system to switch between bash versions on a Mac. I have this which works:

change_bash_version(){ if test "$1" == "3"; then export PATH="$HOME/bash/versions/3.2.57:${PATH}" elif test "$1" == "4"; then export PATH="$HOME/bash/versions/4.4.18:${PATH}" else export PATH="$HOME/bash/versions/5.0:${PATH}" fi } export -f change_bash_version 

I tried using aliases but they are not inherited - my question is - is there an alternative to changing the PATH to putting the desired bash executable in front? It doesn't work very easily to put an entire directory on the PATH if that dir has a bunch of extraneous files that I don't want the PATH to see.

The other downside to this technique is having to use a bash function to switch versions (unless someone can think of way to use a command line utility).

I tried using this:

change_bash_version(){ bash(){ $HOME/bash/versions/4.4.18/bash "$@" } export -f bash; # error here } 

but bash did not like that - saying "bash" is not a function

Source Link
Alexander Mills
  • 10.9k
  • 27
  • 120
  • 214

Since aliases are not inherited, is there any alternative to exporting the executable on the PATH?

I am trying to setup a system to switch between bash versions on a Mac. I have this which works:

change_bash_version(){ if test "$1" == "3"; then export PATH="$HOME/bash/versions/3.2.57:${PATH}" elif test "$1" == "4"; then export PATH="$HOME/bash/versions/4.4.18:${PATH}" else export PATH="$HOME/bash/versions/5.0:${PATH}" fi } export -f change_bash_version 

I tried using aliases but they are not inherited - my question is - is there an alternative to changing the PATH to putting the desired bash executable in front? It doesn't work very easily to put an entire directory on the PATH if that dir has a bunch of extraneous files that I don't want the PATH to see.

The other downside to this technique is having to use a bash function to switch versions (unless someone can think of way to use a command line utility).