0

I have a script that has a given number of input variables. I would like to detect if all of the variables have been given and quit otherwise. For example lets say the script has 10 input args but only 6 are given. Then I would like to quit. I tried

arg1=$1
arg2=$2
...
arg10=$10
for i in $(eval echo {$1..$10}); do
   echo "$i"
   if [[ -z "$i" ]]; then
       echo 'wrong number of args'
       exit 2
   fi
done

The echo inside the loop (echo "$i$") prints out but the loop always exits. So I have some basic flaw.

2
  • if [ "$#" -ne 10 ]; then echo 'Wrong number of args' fi Commented Sep 14, 2020 at 15:46
  • For some reason this doesnt work. It always exits whether or not I have the right number of args. Commented Sep 14, 2020 at 15:53

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.