0
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.

1
  • I have another question with all the codes I tried, but as noone has a solution, I am posting the plain question to see if someone would get less confused with the plain question, please see my other question to the codes, I have tried. Thank you. Commented Apr 18, 2011 at 12:27

1 Answer 1

1
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.

Sign up to request clarification or add additional context in comments.

1 Comment

Sorry about that comment, but how can this script that doesn't even execute and after being fixed, doesn't either answer to the question asked can be upvoted and accepted ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.