Created
July 26, 2017 03:18
-
-
Save jenux/e8260868e6116b83393edf697c22a51e to your computer and use it in GitHub Desktop.
bash usage sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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