Skip to content

Instantly share code, notes, and snippets.

@ynonp
Created June 3, 2012 09:02
Show Gist options
  • Save ynonp/2862674 to your computer and use it in GitHub Desktop.
Save ynonp/2862674 to your computer and use it in GitHub Desktop.
Case bash example
#!/usr/bin/env bash
#
# show
# Hello Mr. Anonymous. You work at UNKNOWN COMPANY
#
# show -name Mike
# Hello Mr. Mike. You work at UNKNOWN COMPANY
#
# show -job Intel
# Hello Mr. Anonymous. You work at Intel
#
# show -name Mike -job Intel
# Hello Mr. Mike. You work at Intel
#
NAME=Anonymous
JOB="UNKNOWN COMPANY"
while [[ $# -gt 0 ]]
do
case $1 in
-name) NAME=$2; shift 2;;
-job) JOB=$2; shift 2;;
*) echo "Unknown Argument: $1"; exit;;
esac
done
echo Hello Mr $NAME. You work at $JOB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment