if ( a == 5 && b == 6 ) like expressions
Hi all,
I somehow couldn't find the "linux bash script" equivalent of this C expression. How do we bind several comparisons together in bash script? Best, Bekir |
The 'test' command is used in bash for this. You can do 'man test' to see its syntax. The '[' command is equivalent to test:
if [ $a = 5 -a $b = 6 ]; then echo "condition true" else echo "condition false" fi |
Thanks Udi, I know it is such a simple question..
But I still couldn't get it working with "test", I mean it is not clarified in the manual, how to bind several expressions together. Would you have time to write the example with "test"? Regards, Bekir |
The same example with test is the same as the previous example:
if test $a = 5 -a $b = 6 ; then echo "condition true" else echo "condition false" fi From the manual page: EXPRESSION1 -a EXPRESSION2 both EXPRESSION1 and EXPRESSION2 are true |
Quote:
Code:
if [ $foo -eq 5 -a $boo -eq 10 ]; then Code:
if [ $foo -eq 5 -o $boo -eq 10 ]; then That's how I always use it. And it works. Maybe there's some other way to use AND/OR expressions but I don't care. This has worked for me. Hope I helped. |
I got it working..! :)
Both helps are greatly appreciated.. Thanks a lot for your time.. Best, Bekir |
Quote:
You can always concatenate two tests, which I use sometimes for the sake of clarity, but it's probably less efficient. Code:
if [ $foo == 5 ] && [ $boo == 1 ]; then echo ok; fi |
All times are GMT -5. The time now is 04:05 PM. |