The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
IF condition failing in a SSH script rubionis Shell Programming and Scripting 9 11-21-2007 04:17 PM
script to check for a condition inside a file kiran1112 Shell Programming and Scripting 11 03-21-2007 09:38 AM
need help with test condition in shell script pieman8080 Shell Programming and Scripting 9 09-11-2006 05:20 PM
awk script to split a file based on the condition superprogrammer Shell Programming and Scripting 12 06-14-2005 03:59 AM
OR'ing condition in script vino Shell Programming and Scripting 9 04-21-2005 08:34 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-07-2008
yog_chavan yog_chavan is offline
Registered User
  
 

Join Date: May 2008
Posts: 2
Shell script - If---fi condition

Hi All,

My current if statement is like mentioned below. But there is posibility that plant value which are currently only two i.e. ESAP and VAL will be more. I do not want to add OR condition every time. Is there any way, I can use only one bracket and go on adding new values. something like this.
if [ $PLANT eq ESAP VAL VAL1 VAL2......]. I am not aware of exact syntax. Could you please let me know.
================================
if [ $PLANT = ESAP -o $PLANT = VAL ]
then
do something
else
do something
fi
================================
  #2 (permalink)  
Old 05-07-2008
aju_kup aju_kup is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 189
HTML Code:
if [ $PLANT == ESAP -o $PLANT == VAL ]
then
do something
else
do something
fi
  #3 (permalink)  
Old 05-07-2008
yog_chavan yog_chavan is offline
Registered User
  
 

Join Date: May 2008
Posts: 2
hi aju kup

I dont want to keep on adding OR condition. If anybody aware of basic SQL, then there it is possible to mention like..

PLANT IN ( 'ESAP','VAL','VAL1,'VAL2'...........)

Something like this possible????
  #4 (permalink)  
Old 05-07-2008
aju_kup aju_kup is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 189
Code:
plant="ESAP VAL VAL1 VAL2"

echo $plant | grep ESAP >/dev/null

if [ $? == 0 ]
then
do something
else 
do something
fi
  #5 (permalink)  
Old 05-07-2008
denn denn is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 96
this is what case statements are for.

Code:
#!/usr/bin/ksh
PLANT=$1

case $PLANT in

        ESAP|VAL)
                print do something
                ;;
        *)
                print do nothing
                ;;
esac
$ ./match VAL
do something
$ ./match ESAP
do something
$ ./match abc
do nothing
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:58 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0