how to make sure that N+1 argument is present when Nth argument is equal
to "--check"
I am trying to write code to check if any argument (on position N) is
equal to "--check" and, if its true, require that next argument (position
N+1) is present. Otherwise, exit.
How can i achieve that?
i am trying sth like this but it doesnt seem to work: i am reiterating
arguments and if "--check" is found then setting FLAG to 1 which triggers
another conditional check for nextArg:
FLAG=0
for i in "$@"; do
if [ $FLAG == 1 ] ; then
nextARG="$i"
FLAG=0
fi
if [ "$i" == "--check" ] ; then
FLAG=1
fi
done
if [ ! -e $nextARG ] ; then
echo "nextARG not found"
exit 0
fi
No comments:
Post a Comment