shell - Bash case statement -


i'm trying learn case write functional script.

i'm starting off below

#!/bin/sh case $@ in      -h|--help)             echo "you have selected help"             ;;     -b|-b)             echo "you have selected b"             ;;     -c|-c)             echo "you have selected c"             ;;       *)             echo "valid choices a,b,c"             exit 1             ;; esac 

i want use 2 of these options:

./getopts.sh -h -c 

but result valid choices a,b,c

please can out , let me know i'm doing wrong?

i want build script if enter 1 option multiple things if enter multiple.

also how parse $1 script surley ever option enter first (-h) $1 ??

thanks!

try this

#!/bin/sh  usage() {     echo `basename $0`: error: $* 1>&2     echo usage: `basename $0` '[-a] [-b] [-c]          [file ...]' 1>&2     exit 1 }   while :     case "$1" in     -a|-a) echo picked a;;     -b|-b) echo picked b;;     -c|-c) echo picked c;;     -*) usage "bad argument $1";;     *) break;;     esac     shift done 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -