Skip to content

Instantly share code, notes, and snippets.

@jenux
Created July 26, 2017 03:18
Show Gist options
  • Select an option

  • Save jenux/e8260868e6116b83393edf697c22a51e to your computer and use it in GitHub Desktop.

Select an option

Save jenux/e8260868e6116b83393edf697c22a51e to your computer and use it in GitHub Desktop.
bash usage sample
usage() {
echo "Usage: $0 [-s <45|90>] [-p <string>]" 1>&2; exit 1;
}
while getopts ":s:p" o; do
case "${o}" in
s)
s=${OPTARG}
((s == 45 || s == 90)) || usage
;;
p)
p=${OPTARG}
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
if [ -z "${s}" ] || [ -z "${p}" ]; then
usage
fi
echo "s = ${s}"
echo "p = ${p}"
usage() {
cat <<EOF
Usage: $0 [-s <45|90>] [-p <string>]
Arguments:
-s: xxx
-p: xxx
Examples:
1.
2.
EOF
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment