PDA

View Full Version : [SOLVED] problem in bash script



oren tal
November 18th, 2010, 03:35 PM
I have written a script and I get error and I don't understand why.


neededParameters=2
numOfParameters=0
correctNum=0
while getopts "s:l:" opt
do
case "$opt" in
s)
serviceName= $OPTARG #errorline 1
numOfParameters= $numOfParameters + 1
;;
l)
fileName= $OPTARG #errorline 2
numOfParameters= $numOfParameters + 1
;;
?)
echo "unknown option"
;;
esac
done
when I run:
script -s s -l l
Then I get error message on errorlines 1 and 2 that it doesn't recognize s and l.

I would be really glad for an help.
Thanks in advance.

jpl888
November 18th, 2010, 04:06 PM
Did you try removing the quotes from
"s:l:"?

gmargo
November 18th, 2010, 04:47 PM
FIxed addition and removed space:



neededParameters=2
numOfParameters=0
correctNum=0
while getopts "s:l:" opt
do
case "$opt" in
s)
serviceName=$OPTARG
numOfParameters=$(($numOfParameters + 1))
;;
l)
fileName=$OPTARG
numOfParameters=$(($numOfParameters + 1))
;;
?)
echo "unknown option"
;;
esac
done

oren tal
November 21st, 2010, 10:09 AM
FIxed addition and removed space:



neededParameters=2
numOfParameters=0
correctNum=0
while getopts "s:l:" opt
do
case "$opt" in
s)
serviceName=$OPTARG
numOfParameters=$(($numOfParameters + 1))
;;
l)
fileName=$OPTARG
numOfParameters=$(($numOfParameters + 1))
;;
?)
echo "unknown option"
;;
esac
done

Thanks.