I have a use case in which I have to execute functionality of different methods in shell script. User will call my shell script as I have to read the value of options and on basis of it have to call methods. Please find the sample code below.
./testfile.sh --option1 value1 --option2 value2
#!/bin/bash
#
# Example of how to parse short/long options with 'getopt'
#
OPTS=`getopt --long option1,option2 -n 'parse-options' -- "$@"`
if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; exit 1 ; fi
echo "$OPTS"
eval set -- "$OPTS"
opt=""
id=""
while true; do
echo "Inside while $1 $2"
case "$1" in
--option1) echo $1; shift ;;
--option2 ) echo $2; shift ;;
-- ) shift; break ;;
* ) break ;;
esac
done
echo "Value for opt $opt"
echo "Value for id $id"