Skip to content

Instantly share code, notes, and snippets.

@cdpath
Created March 9, 2016 07:40
Show Gist options
  • Save cdpath/4b4994c3275fa1e6868d to your computer and use it in GitHub Desktop.
Save cdpath/4b4994c3275fa1e6868d to your computer and use it in GitHub Desktop.
bash 模板
#!/bin/bash
echo "OPTIND starts at $OPTIND"
while getopts ":pq:" optname
do
case "$optname" in
"p")
echo "Option $optname is specified"
;;
"q")
echo "Option $optname has value $OPTARG"
;;
"?")
echo "Unknown option $OPTARG"
;;
":")
echo "No argument value for option $OPTARG"
;;
*)
# Should not occur
echo "Unknown error while processing options"
;;
esac
echo "OPTIND is now $OPTIND"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment