I have written the following two functions in Bash:
function prepend_path() { PATH=$1:$PATH }
function prepend_manpath() { MANPATH=$1:$MANPATH }
The bodies of the functions are actually going to be more complicated. To avoid code duplication, I would like to do something like the following:
function prepend() { "$1"=$2:"$1" }
function prepend_path() { prepend PATH $1 }
function prepend_manpath() { prepend MANPATH $1 }
However, prepend
is not valid Bash. The idea is to pass the name of an environment variable as an argument to Bash. Is it possible, or is there another solution?