if [ [ $a == $b + $c ] || [ $b == $a + $c ] || [ $c == $a + $b ] ]; then

result: too many arguments
What is the proper syntax?


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:


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



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

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

I hope this helps!


Thank you. Much appreciated!


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"
echo "Not match"