Since it's Bash, you can append to a string (var+=value
). Though you pretty much need a temporary variable here, since you're prefixing the paths to the original value.
tmp=/usr/local/cuda/lib
tmp+=:$HOME/anaconda2/lib
tmp+=:/usr/local/lib
tmp+=:/usr/lib
tmp+=:/opt/intel/compilers_and_libraries/mac/lib
tmp+=:/opt/intel/mkl/lib
export DYLD_FALLBACK_LIBRARY_PATH=$tmp:$DYLD_FALLBACK_LIBRARY_PATH
unset tmp
Note that like your original snippet, this assumes that DYLD_FALLBACK_LIBRARY_PATH
is not empty in the beginning. If it is, this'd leave a trailing :
in it.
Alternatively, if your paths don't contain whitespace just put the string in quotes, and remove the whitespace afterwards:
export DYLD_FALLBACK_LIBRARY_PATH="/usr/local/cuda/lib:
$HOME/anaconda2/lib:
/usr/local/lib:/usr/lib:
/opt/intel/compilers_and_libraries/mac/lib:
/opt/intel/mkl/lib:
$DYLD_FALLBACK_LIBRARY_PATH"
DYLD_FALLBACK_LIBRARY_PATH=${DYLD_FALLBACK_LIBRARY_PATH//[[:space:]]}
This is a bit silly:
prepend() { declare -n _n=$1; _n="$2$_n"; }
prepend DYLD_FALLBACK_LIBRARY_PATH /opt/intel/mkl/lib:
prepend DYLD_FALLBACK_LIBRARY_PATH /opt/intel/compilers_and_libraries/mac/lib:
prepend DYLD_FALLBACK_LIBRARY_PATH /usr/lib:
prepend DYLD_FALLBACK_LIBRARY_PATH /usr/local/lib:
prepend DYLD_FALLBACK_LIBRARY_PATH "$HOME/anaconda2/lib:"
prepend DYLD_FALLBACK_LIBRARY_PATH /usr/local/cuda/lib:
export DYLD_FALLBACK_LIBRARY_PATH
$
to make it$DYLD_FALLBACK_LIBRARY_PATH
?