code explanation

Can you please explain the following code plz?

my_cd=' '
while getopts :e: OPTION;
do 
  case "$OPTION" in
    e) my_cd ="$OPTARG";;
  esac
done
 
if [ -z "my_cd"] ; then
  echo " >>> ERROR - I am wrong"
  echo " >>> ERROR - Hello"
  exit 99
fi

What I don't understand is what is OPTION or OPTARG...is this unix thing or ...but I believe e is generated as a code...plz help I need to understand this to proceed?

THanks in advance

getopts is a (nice) way to get the options given on commandline.

The best explanations and examples i know is there : Linux tip: Bash parameters and parameter expansions

Frans,

Thanks for your answer. But can you please explain me the code...i hardly use unix until i really require too so pretty out of touch. Thanks again for your help.

For better comprehension, code must be surrounded by code tags (use the '#' in the editor)

my_cd=' '
# getopts must be used in a loop to look for matches between command line options and the options string.
while getopts :e: OPTION # for each iteration, put the value of command lione option in the variable OPTION
do
    case $OPTION in
        e) my_cd ="$OPTARG" ;; # puts the value of OPTARG in my_cd
              # OPTARG is the string following the option in the command line
              # Example : myscript -e /home/user 
              # The script will detect the option -e and put "/home/user" in OPTARG
    esac
done
 if [ -z "$my_cd"] # if that string is blank ($ to get the value of the variable)
then
    echo " >>> ERROR - I am wrong"
    echo " >>> ERROR - Hello"
    exit 99  # quits with error code 99 (0 would be no error)
fi