Pergunta

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=
Foi útil?

Solução

You need a colon after r if you want it to take an argument:

while getopts "r:" optionName
                ^
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top