learnerNo1
learnerNo1

Reputation: 147

Unix ksh validation

echo banana apple pear grape melon orange lime
read fruit1 fruit2 fruit3

Questions: - How to test if the user input 3 arguments and not less? - How to test if the 3 arguments are in the list or if it is 3 out of these seven?

I read many things on the internet, I tried playing with s#, nothing is working.

Upvotes: 0

Views: 213

Answers (1)

Vijay
Vijay

Reputation: 67291

i=0
for var in "banana apple pear grape melon orange lime read fruit1 fruit2 fruit3"
if [ "$var" == "$2" -o "$var" == "$3" -o "$var" == "$4" ]
then
++$i
fi


echo $i

if value of i is 3 then it means all the three command line arguments are present.

Upvotes: 1

Related Questions