Problem in using AND OR condition together

a=rhino
b=crocodil
c=testsc
if [ [ "$a" = rhino || "$b" = crocodile ] && "$c" = testsc ]
then
echo "Test #5 succeeds."
else
echo "Test #5 fails."
fi

i need to test or condition before check the output with AND condition. ur help is much appreciated...

Something Like this :

if [  "$a" = rhino -o  "$b" = crocodile  -a  "$c" = testsc ]
then
echo "Test #5 succeeds."
else
echo "Test #5 fails."
fi

Same problem... tried using something like this

[ [ [ 0 = 0 ] -o [ 1 = 1] ] -a [ 0 = 0 ].

This gives a syntax error.

S

Try this:

if ([ "$a" = rhino ] || [ "$b" = crocodile ]) && [ "$c" = testsc ]

This should work. Note protecting the parentheses in the "if" statement, enclosing strings in double quotes, and using single square brackets. Note spelling "crocodile" the same way in $b !

#!/bin/ksh
a="rhino"
b="crocodile"
c="testsc"
if [ \( "$a" = "rhino" -o "$b" = "crocodile" \) -a "$c" = "testsc" ]
then
        echo "Test #5 succeeds."
else
        echo "Test #5 fails."
fi

Thanks a ton!
Both of them worked.
I am really confused at the way [] and () works....

Mine and franklin52 solutions look similar but are actually very different.

franklin52 is using a "regular expression" - see "man 5 regexp" (and "man" for your shell) within a sub-shell (enclosed by parentheses) and testing the success or failure with the "&&" operative before using a "test" for the right hand side of the and.

I am just using a "test" - see "man 1 test" (and "man" for your shell) with parentheses overriding the default execution order of the ands and ors. Similar to a mathematical function. The parentheses are escaped so they will be passed to "test" rather than being actioned by the shell.

Thus the use of parentheses is totally different syntax, but the use of single square brackets to enclose a condition is similar.

Just seen the mans you suggested. Both of your solutions are really diffent.
Thanks
S

if [ "$a" = "rhino" ] || [ "$b" = "crocodile" ] && [ "$c" = "testsc" ]

cfajohnson solution has shown that the parentheses in Frankin52's solution only clarified the command line.

IMHO the OP wants to test this condition (in C style):

if (( "a" == rhino || "b" == crocodile ) && "c" == testsc )

The order of the test statements is significant, in the examples above the parentheses doesn't matter, but check the output of these commands:

$ bash --version
GNU bash, version 3.1.17(1)-release (i486-pc-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.
$
$
$ if [ "a" = "b" ] && ([ "b" = "b" ] || [ "a" = "a" ]); then echo YES; fi
$
$ if [ "a" = "b" ] && [ "b" = "b" ] || [ "a" = "a" ]; then echo YES; fi
YES
$

Regardless of the precedence the parentheses make the condition more readable.
I quite like the idea of bracketing both sizes of the and (&&):

if ([ "a" = "b" ]) && ([ "b" = "b" ] || [ "a" = "a" ]); then echo YES; fi