The following while statement loops through all the options and sets them to the corresponding variable. getopts returns true while there are options to be processed. The argument string, here "lme:h", specifies which options the script accepts. If the user specifies an option which is not in this string, it will go into * section which will display a help to use this script with examples. If the option is succeeded by a colon, the value immediately following the option is placed in the variable $OPTARG.
while getopts "lme:h" option; do
case "$option" in
l) ListFiles=1;;
m) MoveFiles=1;;
e) email="$OPTARG";;
h|*) helpFunction;;
esac
done

Script Call:
-----------------------------------------------------------------------------------------------------------------------------------------------ExampleScript.sh -l#It will go into case l) and set ListFiles=1.ExampleScript.sh -m#It will go into case m) and set MoveFiles=1.ExampleScript.sh -m -e "example@gmail.com"#It will go into case m) and e) and set MoveFiles=1as well as get the email address in $Ovariable and set it to "email" variable.

ExampleScript.sh -h#It will go into case h|*) and call the function helpFunction to show help.ExampleScript.sh -<anything apart from optstringname we have provided>#It will also go into case h|*) and will be treated as "*" and show the help. ------------------------------------------------------------------------------------------------------------------------------------------------

Planet MySQL

PHP Camp

About Me

Life is an eternal quest about knowing oneself. It's time to challenge
yourself, to rediscover your hidden traits, talents, and tendencies.
Several inconvenient questions, which you have swept under the carpet,
might resurface.