You need a colon after r
if you want it to take an argument:
while getopts "r:" optionName
^
Question
Below is the snippet of my shell script
#!/bin/sh -e
ROOT=""
while getopts "r" optionName;
do case $optionName in
r)
ROOT="$OPTARG"
;;
*)
echo "Bad argument"
exit
;;
esac
done
echo "ROOT=$ROOT"
it doesn't print the ROOT correctly, where is the problem?
$myscript.sh -r FOO
ROOT=
Solution
You need a colon after r
if you want it to take an argument:
while getopts "r:" optionName
^