Examples:
Code:
$ ./test.sh -a -c 2
operator is -gt
remcount is
^ value missing!
Code:
$ ./test.sh -b -c 2
operator is -lt
remcount is
^ value missing!
Yet when "-c" is the first argument, its value is present:
Code:
$ ./test.sh -c 2 -b
operator is -lt
remcount is 2
What could I do to ensure the value of "-c" is picked up regardless of the argument order?
Script:
Code:
#!/bin/bash
while [ "$1" ]; do
case "$1" in
-a|--above)
shift
operator="-gt"
;;
-b|--below)
shift
operator="-lt"
;;
-c|--count)
shift
remcount="$1"
;;
-h|--help)
usage
exit 0
;;
-*)
echo "$(basename $0): invalid option $1" >&2
echo "see --help for usage"
exit 1
;;
*)
break
;;
esac
shift
done
echo operator is $operator
echo remcount is $remcount