LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to do multiple comaprison in a IF statement (http://www.linuxquestions.org/questions/linux-newbie-8/how-to-do-multiple-comaprison-in-a-if-statement-648647/)

pdklinux79 06-11-2008 06:29 PM

How to do multiple comaprison in a IF statement
 
Hi

How to accomplish multiple comaprison in a IF statement?


eg:

if [ $r = 'fail' ] or if [ $r = 'FAIL'] or if [ $r = 'Fail' ]
then
echo the state is $r. please note it
fi


im not able to accomplish this .. giving error.. please let me know how to do it.
thanks

Cuetzpallin 06-11-2008 06:40 PM

You could use "case" instead multiples if

See those links
http://steve-parker.org/sh/case.shtml

http://www.cyberciti.biz/nixcraft/li...ch03sec08.html

weibullguy 06-11-2008 08:08 PM

Try using regular expressions. Something along the lines of
Code:

if [[ $r == [Ff][Aa][Ii][Ll] ]]; then
        echo the state is $r. please note it
fi


chrism01 06-11-2008 09:08 PM

OR:

if [[ $a -eq $b || $a -eq $c .... ]]

AND:

if [[ $a -lt $b && $a -gt $c .... ]]

armanox 06-11-2008 11:34 PM

Quote:

Originally Posted by weibullguy (Post 3181964)
Try using regular expressions. Something along the lines of
Code:

if [[ $r == [Ff][Aa][Ii][Ll] ]]; then
        echo the state is $r. please note it
fi


That's what I was going to say...


All times are GMT -5. The time now is 01:42 PM.