Click to See Complete Forum and Search --> : Bash question..
goon12
12-09-2003, 04:57 PM
I have googled a bit and checkd the NHF's. How in Bash can you check 2 condition...
if [ $foo -ne "30" && $boo -eq "30" ]
then
commands...
fi
I know that's not right cause it's working, just wondering how I would do something like that?
Thanks,
goon12
goon12
12-09-2003, 05:15 PM
Sorry I found it 1 minute after I posted
bsh152s
12-09-2003, 05:46 PM
For those searching the forums later, the correct fix is using double brackets.
if [[ $foo -ne "30" && $boo -eq "30" ]]
then
commands...
fi
bwkaz
12-09-2003, 07:41 PM
But:
if [ $foo -ne 30 -a $boo -eq 30 ]
then
commands...
fi is portable to shells other than bash. I don't think the original Bourne shell (/bin/sh) knows how to parse double square brackets (though of course I haven't tried it). A single square bracket is equivalent to /bin/test, usually (unless your shell treats it as a builtin), since you have a symlink from /bin/[ to /bin/test.
/bin/test knows that -a means "and", and -o means "or".
bsh152s
12-09-2003, 07:50 PM
Good info to know. All in all, even if you solve the problem yourself, post the solution.
goon12
12-09-2003, 09:18 PM
Weird.. I was using this and it seemed to work
if [ $upalert -eq "1" ] && [ $res -eq "30" ]
then
...
fi
Either way, Thanks.
bwkaz
12-09-2003, 11:30 PM
Oh, right, if understands &&. I don't know for sure if all Bourne shells' if's understand &&, though... they might.