Hello There,
I'm having an issue using
getopts in my bash script.
For trouble shooting purposes I've make it simple:
Code:
#!/bin/bash
while getopts ":f:p:d:g:a" OptionArgument; do
case $OptionArgument in
p ) productdb=${OPTARG};;
d ) debug="1";;
f ) cdtFile=${OPTARG};;
g ) generic="1";;
a ) a="just another one just for test";;
\?) echo = "No option specify";;
* ) echo = "wrong variable";;
esac
done
echo "product = ${productdb}"
echo "cdtFile = ${cdtFile}"
echo "debug = ${debug}"
echo "generic = ${generic}"
echo "a= ${a}"
In my example
p and
f will be optional and
a is just for testing.
below is an example of what I type and the output:
Code:
$ ./1_analysing -d -g -a -pimsx -ffileName
product = imsx
cdtFile = fileName
debug = 1
generic =
a= just another one just for test
the generic value stay empty
which I don't why.
I've found many example on internet but none of them are working as expected.
Is there a bug some where or did I miss something?
Thanks for your help;
Angel.