I'm supporting below arguments to the script. I want to find out duplicate arguments when its passed and throw an error. Can you please help me.
#! /bin/sh
VCFile=
gCFFile=
PW=xyzzy
while test $# -gt 0
do
option=$(echo $1 | tr a-z A-Z)
case $option in
(-VO) shift
VCfile=$1
;;
(-CON) shift
gCFFile=$1
;;
(-PASSWORD) shift
PW=$1
;;
(*)
print "\nerror -The command line argument $1 is invalid\n"
print "Testscript has aborted.\n"
exit 2
;;
esac
shift
done
./Install.sh -VO abc.txt -CON tt.txt - pass
./Install.sh -VO abc.txt -CON tt.txt -ss
error -The command line argument -ss is invalid
Testscript has aborted.
if running with dup parameters like below
./Install.sh -VO abc.txt -CON tt.txt -CON ta.txt -PASSWORD ABC -PASSWORD non
--doesn't fail , Here I want to throw an error as duplicate options are entered.