1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| #!/bin/bash
# define usage info usage() { cat <<EOF Usage: $0 [-a] [-b name] msg EOF }
while getopts ":ab:Bc:" opt; do case $opt in a) echo "found -a" ; a="hello" ;; b) echo "found -b and value is: $OPTARG" ;; c) echo "found -c and value is: $OPTARG" ;; *) usage ;; esac done
shift $(($OPTIND - 1))
echo "MSG: $1"
if [ -n "${a}" ] ; then # or [ ! -z "${a}" ] echo "-a exists : ${a}" else echo "-a not exists" fi
|