Skip to content

Instantly share code, notes, and snippets.

@turbod
Created September 8, 2012 15:46
Show Gist options
  • Save turbod/3676227 to your computer and use it in GitHub Desktop.
Save turbod/3676227 to your computer and use it in GitHub Desktop.
Processing options and parameters with getopts
#!/bin/zsh
# processing options and parameters with getopts
while getopts :a:b:cd opt
do
case "$opt" in
a) echo "The -a option, value $OPTARG";;
b) echo "The -b option, value $OPTARG";;
c) echo "The -c option";;
d) echo "The -d option";;
*) echo "Unknown option: $opt";;
esac
done
shift $[ $OPTIND - 1 ]
count=1
for param in "$@"
do
echo "Parameter $count: $param"
count=$[ $count + 1 ]
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment