LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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: 164

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 14.2
Posts: 2,815
Blog Entries: 1

Rep: Reputation: 261Reputation: 261Reputation: 261
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
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:03 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration