#!/bin/bash if [ [ $a == $b + $c ] || [ $b == $a + $c ] || [ $c == $a + $b ] ]; then
result: too many arguments
What is the proper syntax?
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:
#!/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!
Thank you. Much appreciated!
You can use it simply by
if [ $a -eq $((b+c)) -o $c -eq $((a+b)) ]; then
for a brief summary of linux comparison operators have a look at
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"
Hi, as I was told that my code doesn’t scale well at all, I thought perhaps I’d try to get a better understanding of interfaces/abstract classes and classes and the relationship between them.
I don’t want at this stage work on a big separate project as I've already got plenty ...
OK, so HostGator for some reason no longer allows gcc/g++ access unless you have a Designated Server account, which is a lot of money to spend just to compile my "Hello World" program. Thus I figured I'd compile at home, then upload. Program is your regular old bare-bones Hello World ...
Hi. I have a form with list box : lst_product, datagridview : grd_order and button: btn_addline. lst_product has a list of product ids selected from database (MS Acess 2013) , grd_order is by default empty except for 2 headers and btn_addline adds rows to grd_order.
Private Sub btn_addline_Click(ByVal ...