Skip to content

Instantly share code, notes, and snippets.

@h2onda
Last active September 30, 2015 14:58
Show Gist options
  • Select an option

  • Save h2onda/1811258 to your computer and use it in GitHub Desktop.

Select an option

Save h2onda/1811258 to your computer and use it in GitHub Desktop.
getopts usage sample
#!/bin/bash
usage() {
echo "$(basename $0) [options] args"
}
while getopts 'p:fh' args "$@"
do
case $args in
p)
PARAM=$OPTARG
;;
f)
FLAG=true
;;
h|?)
usage
exit 1
;;
esac
done
shift $(($OPTIND - 1))
echo "\$PARAM=$PARAM \$FLAG=$FLAG \$*=\"$*\""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment