Skip to content

Instantly share code, notes, and snippets.

@maxpeterson
Created September 24, 2012 09:31
Show Gist options
  • Select an option

  • Save maxpeterson/3775120 to your computer and use it in GitHub Desktop.

Select an option

Save maxpeterson/3775120 to your computer and use it in GitHub Desktop.
Run a shell with environment variables set.
#!/bin/bash
display_usage() {
echo -e "\nUsage: $0 [command] \n"
echo -e "Execute the specified command with environment variables set."
echo -e "If no command is specified then execute a new shell.\n"
}
if [[ ( $1 == "--help") || $1 == "-h" ]]; then
display_usage
exit 0
fi
# Get path to this script
root=$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
# Set the environment
if [ -e $root/env ]; then
source $root/env;
fi
# Start a new shell (with the environment).
# Pass any arguments to the shell. If no arguments are supplied then start an
# interactive shell (using -i)
if [ $# -eq 0 ] ; then
echo "Starting interactive shell with new environment."
echo "Type exit or Control-D to return to the previous shell."
exec $SHELL -i
else
exec $@
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment