LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 06-11-2008, 05:29 PM   #1
pdklinux79
LQ Newbie
 
Registered: Jun 2008
Posts: 29

Rep: Reputation: 15
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
 
Old 06-11-2008, 05:40 PM   #2
Cuetzpallin
Member
 
Registered: Feb 2008
Location: Monterrey, MX
Distribution: Slackware since 3.4 and love it!!!
Posts: 162

Rep: Reputation: 31
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
 
Old 06-11-2008, 07:08 PM   #3
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware-current, Cross Linux from Scratch, Gentoo
Posts: 2,693
Blog Entries: 1

Rep: Reputation: 217Reputation: 217Reputation: 217
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
 
Old 06-11-2008, 08:08 PM   #4
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,225

Rep: Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021
OR:

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

AND:

if [[ $a -lt $b && $a -gt $c .... ]]
 
Old 06-11-2008, 10:34 PM   #5
armanox
Member
 
Registered: Sep 2005
Location: Baltimore, MD, USA
Distribution: Fedora, Gentoo, Debian, Slackware, IRIX, OS X
Posts: 192

Rep: Reputation: 32
Quote:
Originally Posted by weibullguy View Post
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...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Case statement with If statement cbo0485 Linux - Newbie 4 11-07-2007 08:05 PM
Multiple Autologins; Multiple Users; Multiple Sessions mrclisdue Linux - Desktop 1 09-26-2007 05:50 AM
bash case statement with multiple command line options pwc101 Programming 16 06-01-2007 11:43 AM
For Statement bendeco13 Linux - General 6 10-31-2004 05:31 PM
If Statement junjem0702 Programming 4 08-23-2004 09:49 AM


All times are GMT -5. The time now is 10:36 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration