Last active
December 12, 2015 03:09
-
-
Save EuphoryX1/4705038 to your computer and use it in GitHub Desktop.
This file contains 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 | |
while getopts a:bc: flag; do | |
case $flag in | |
a) | |
opt_a=$OPTARG | |
;; | |
b) | |
opt_b=1 | |
;; | |
c) | |
opt_c=$OPTARG | |
;; | |
?) | |
echo "usage: ...." | |
exit 1 | |
;; | |
esac | |
done | |
shift $(( OPTIND - 1 )); | |
echo $* | |
## | |
## bash -x ~/work/bash_test/test_getopts.sh -a 1 -b -c a arg1 arg2 result below | |
+ getopts a:bc: flag | |
+ case $flag in | |
+ opt_a=1 | |
+ getopts a:bc: flag | |
+ case $flag in | |
+ opt_b=1 | |
+ getopts a:bc: flag | |
+ case $flag in | |
+ opt_c=a | |
+ getopts a:bc: flag | |
+ shift 5 | |
+ echo arg1 arg2 | |
arg1 arg2 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment