0

I have a requirement where in, I need to use a certain set of values, under a Nested if condition. I am trying to implement it using a for loop, but not able to put a correct syntax.

eg.

if [ "$i" -ge 353 ] && [ "$i" -lt 385 ]
then
   for((m=7001;m<7016;m++))
value=$m
done
fi

Is this a correct syntax?

1 Answer 1

5

You need an extra do for the for loop. Formatting it makes it more clear:

if [ "$i" -ge 353 ] && [ "$i" -lt 385 ]
then
   for((m=7001;m<7016;m++))
   do
      value=$m
   done
fi

Note that all these while, for, etc need to be wrapped with do and done:

while #something
do
    things
done

for #condition
do
    things
done

'done' indicates that the code that used the value of $i has finished and $i can take a new value.

And for the if:

if #condition; then
    things
fi
Sign up to request clarification or add additional context in comments.

1 Comment

Hmm, I'm surprised bash allows for((...)) without a space after "for"

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.