Skip to content

Instantly share code, notes, and snippets.

@AnderRasoVazquez
Forked from redtower/checkparam-1.sh
Last active October 3, 2018 14:51
Show Gist options
  • Save AnderRasoVazquez/16d460f646e949201ca9 to your computer and use it in GitHub Desktop.
Save AnderRasoVazquez/16d460f646e949201ca9 to your computer and use it in GitHub Desktop.
[Getopts in Bash] #bash #shell
#!/bin/sh
while getopts ab:c: opt
do
case $opt in
a)
flga=1
;;
b)
flgb=1
optb=$OPTARG
;;
c)
flgc=1
optc=$OPTARG
;;
\?)
;;
esac
done
shift $(($OPTIND - 1))
#!/bin/sh
OPT=`getopt -n $0 -o ab:c: --long aaa,bbb:,ccc: -- "$@"`
eval set -- "$OPT"
while true;
do
case $1 in
-a|--aaa)
opt_a=true
;;
-b|--bbb)
opt_b=$2
;;
-c|--ccc)
opt_c=true
;;
--)
break
;;
esac
shift
done
echo $opt_a
echo $opt_b
echo $opt_c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment