Open GoogleCodeExporter opened 9 years ago
The problem arises from shifting the positional parameters by 2 places. The
line
"shift 2" is used in the while-loop to grab the next pair of arguments while
maintaining the same identifiers, $1 and $2. Unfortunately, '-h' and '-v'
appear
alone causing issues like an infinite loop after shifting outside the list of
input
parameters.
One fix is to declare a local variable (here "n") to help determine how many
positions to shift depending on the flag being handled. Below is a snippet of
the
declaration of "n" and a while-loop containing the working fix.
local n=0
while [ `echo $1 | grep "-"` ]; do
case $1 in
-h|--help) echo "this is the help text";n=1;;
-v|--version) echo "demo19worker version 0.0001";n=1;;
-s|--sortby) sortby=$2;n=2;;
-i|--ignore) ignore=$2;n=2;;
*) blabln "'"$1"' unknown\n usage demo19worker [options]";
return 0;;
esac
shift $n
done
Original comment by Dave.Cas...@gmail.com
on 12 Sep 2007 at 3:26
Original issue reported on code.google.com by
mom...@gmail.com
on 4 Sep 2007 at 7:38