Skip to content

Instantly share code, notes, and snippets.

@danrigsby
Created May 5, 2014 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danrigsby/ac641fce386cddcece3f to your computer and use it in GitHub Desktop.
Save danrigsby/ac641fce386cddcece3f to your computer and use it in GitHub Desktop.
Bash script to install environment variables globally
#!/bin/bash
# example: sudo sh ./install-env-var.sh "FOO=bar" "BAR=foo"
for ARG in "$@"
do
echo "*** installing environment variable: $ARG ***"
export $ARG
if ! grep -q "${ARG}" "$HOME/.profile"; then
echo ${ARG} >> $HOME/.profile
fi
if ! grep -q "${ARG}" "/etc/environment"; then
echo ${ARG} >> /etc/environment
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment