0

I'm having a syntax error with this if block and can't I haven't been able to correct it

if [[ $X >= 100] || [$Y >= 100 ]]
then
   echo "..."
fi

I've rewrote this, but haven't had any luck on finding the correct syntax. Thanks in advance!

4 Answers 4

5

This is a syntax error, you should try :

if ((X >= 100 || Y >= 100 ))
then
   echo "..."
fi

NOTE

  • with this syntax, no need to remember -ge and such. This is just like arithmetic
  • ((...)) is an arithmetic command, which returns an exit status of 0 if the expression is nonzero, or 1 if the expression is zero. Also used as a synonym for let, if side effects (assignments) are needed. See http://mywiki.wooledge.org/ArithmeticExpression
Sign up to request clarification or add additional context in comments.

Comments

3

What you're looking for is this :

if [[ $X -ge 100 || $Y -ge 100 ]];
then
   echo "..."
fi

Comments

2

Your if is fine. Your [[ command is screwed up.

if [[ $X -ge 100 || $Y -ge 100 ]]

Comments

1

You seem to be trying to nest [...] expressions, which is not something you can do in bash. The [[ ... ]] expression is an entirely separate construct available in bash. I won't bother posting a correct expression, as the other answers have that well covered.

Comments

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.