While do case and getopts shell script linux example

While do case and getopts shell script linux example

1. ‘ getopts ‘ is a syntax to get parse command line argument to our script , this also as an option of argument.

2. parse an argument -a, -b to the script.

while getopts “:ab” opt; do
case ${opt} in
a )
option_a=${OPTARG}
echo ” You choose : $option_a”
;;
b )
option_b=${OPTARG}
echo ” You choose : $option_b”
;;
\? ) echo “Usage: cmd [-a] [-b]”
;;
esac
done

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s