I am currently parsing options in a script like that:
while getopts ":ia" OptionArgument; do
case $OptionArgument in
i ) echo "bli";;
a ) echo "bla";;
* ) echo "flag not known";;
? ) echo "unknown parameter";;
esac
done
Every parsing option and flag works - except this one: ? ). So if I call my script with something like ./MyScript hjrfgdskjgh it passes the loop correctly - although it should be catched in the last line with ? ).
I also tried removing quotes from ":ia"or using \? or . ) - nothing works! What do I do wrong??
? character has a special meaning, see http://tldp.org/LDP/abs/html/special-chars.html#WILDCARDQU You can't use it unescaped or unquoted. You have to call the script with ./script.sh -'?' or ./script.sh -\?
* matches anything. Putting anything below it is meaningless, it would only be matched if the * does not match it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With