So, I have a couple of getopts in my bash script. Here is an example of a worker.
FOUND=
SEARCH=
COUNT=0
while getopts "ips:flenkc" OPTION
do
case $OPTION in
i)
FOUND=1
let "COUNT++"
;;
p)
FOUND=2
let "COUNT++"
;;
s)
FOUND=3
SEARCH=$OPTARG
let "COUNT++"
;;
esac
done
Later, a case statement that checks to see if count = 1 (which means that the call uses only one of the following: i, p, and s). Not important, except that it defines the main action.
Now the thing in question. This has worked before, and now it is not. The goal is to make sure that if someone wants to enter data, they can do it with the following bash command.
./programname -i -f Mary -l Sue -e smary@email.com -n 555-555-5555
, -i, -f, -l, -e -n ( , , ).
, : , . bash, , , .
if [ $FOUND == "1" ]
then
echo "You have chosen to insert things."
FIRST=
LAST=
EMAIL=
NUMBER=
while getopts "if:l:e:n:" OPTION
do
case $OPTION in
f)
FIRST=$OPTARG
;;
l)
LAST=$OPTARG
;;
e)
EMAIL=$OPTARG
;;
n)
NUMBER=$OPTARG
;;
esac
done
if [[ -z $FIRST ]] || [[ -z $LAST ]] || [[ -z $EMAIL ]] || [[ -z $NUMBER ]]
echo "Error!!! Some input is missing!!!"
usage // display usage
exit 1
fi
echo -e $FIRST"\t"$LAST"\t"$EMAIL"\t"$NUMBER >> contacts
fi
, FIRST, LAST, EMAIL NUMBER ( , , ).
getopts? , ... !