Created
February 27, 2014 18:19
-
-
Save muupan/9255699 to your computer and use it in GitHub Desktop.
Add a value to an environmental variable while avoiding putting an unnecessary colon.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add a value to an environmental variable while avoiding putting an unnecessary colon. | |
# Usage: add_env_with_colon PATH $HOME/local/bin | |
function add_env_with_colon { | |
ENV_VAR_NAME=$1 | |
VALUE_TO_ADD=$2 | |
CURRENT_VALUE=${!ENV_VAR_NAME} | |
if [ -n "$CURRENT_VALUE" ]; then | |
export $ENV_VAR_NAME=$VALUE_TO_ADD:$CURRENT_VALUE | |
else | |
export $ENV_VAR_NAME=$VALUE_TO_ADD | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment