Created
October 12, 2018 12:57
-
-
Save s1ntoneli/fcd49d473cc4481453a5d5429ea2d751 to your computer and use it in GitHub Desktop.
shell getopt 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
| #!/bin/bash | |
| TEMP=`getopt -o u:p: --long user:,passwd: -n "$0" -- "$@"` | |
| if [ $? != 0 ]; then echo "Terminating..." >&2; exit 1; fi | |
| eval set -- "$TEMP" | |
| while true; do | |
| case "$1" in | |
| -u|--user) echo "User: $2"; shift 2 ;; | |
| -p|--passwd) echo "Password: $2"; shift 2 ;; | |
| --) shift; break ;; | |
| esac | |
| done | |
| echo "Remaining arguments:" | |
| for arg do | |
| echo '--> '"\`$arg'" ; | |
| done | |
| ~ | |
| ~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment