#!/bin/bash
if [ [ $a == $b + $c ] || [ $b == $a + $c ] || [ $c == $a + $b ] ]; then

result: too many arguments
What is the proper syntax?

Thanks!

Hello landog!

I'm not sure exactly where that particular error comes from, but there are a couple of issues with this.

First, when comparing integers you'll want to use the '-eq' operator. Use '=' to compare strings. I think '==' won't work in some shells.

Second, your 'if' statement is enclosed in an extra set of [brackets]. Knock those off and we're one step closer!

Third, and I could be wrong about this, but 'if' won't do math for you. The way to express a math problem in bash is $((x+y)) (or $(($x+$y)) ).

The 'Advanced Bash Scripting Guide' on the tldp.org site is just about the best bash scripting reference out there. Here's a link to the page on operators:

http://tldp.org/LDP/abs/html/comparison-ops.html

Here's a working example (in my shell anyway) of what I think you're trying to express:

#!/bin/bash

a=1
b=1
c=2

if [ $a -eq $((b+c)) ] || [ $b -eq $((a+c)) ] || [ $c -eq $((a+b)) ]; then
   echo 'Looks OK!'
else
   echo 'No Match :-('
fi

In this case the third expression should be true, triggering the 'Looks Ok!' result.

I hope this helps!
-G

Its working only one things we have to take care is bracket, because system does not understand the meaning of given statement if we put wrong bracket in wrong position, so we need to define if with OR logical operator are as follows

if [ $c -eq $((a+b)) ] || [ $c -eq $((a+d)) ]; then

echo "looks ok"
else
echo "Not match"

fi

This article has been dead for over six months. Start a new discussion instead.