Pass parameters as option in custom getopts script in bash -


i'd pass options parameter. e.g.:

mycommand -a 1 -t '-q -w 111' 

the script cannot recognize string in quotes. i.e gets part of string.

getopts works same - see -q.

for custom getopts use similar script (example):

while :     case $1 in         -h | --help | -\?)             # show             ;;         -p | --project)             project="$2"             shift 2             ;;         -*)             printf >&2 'warn: unknown option (ignored): %s\n' "$1"             shift             ;;         *)  # no more options. stop while loop             break             ;;         --) # end of options         echo "end of options"             shift             break             ;;     esac done 

maybe misunderstand question, getopts seems work me:

while getopts a:t: arg     case $arg in         a)  echo "option a, argument <$optarg>"             ;;         t)  echo "option t, argument <$optarg>"             ;;     esac done 

run:

bash gash.sh -a 1 -t '-q -w 111' option a, argument <1> option t, argument <-q -w 111> 

isn't want? maybe missed : after options arguments?


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -