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
problem with if, while, for conditions kittusri9 Shell Programming and Scripting 3 04-24-2008 09:15 AM
multiple conditions in if/then grandtheftander UNIX for Dummies Questions & Answers 4 07-21-2006 01:58 PM
if statement with two conditions cin2000 Shell Programming and Scripting 1 01-23-2006 03:21 PM
if statement with two conditions -e, && yongho Shell Programming and Scripting 16 06-14-2005 04:46 PM
multiple conditions in if statements tim mauger Shell Programming and Scripting 3 04-28-2002 09:42 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-19-2008
audiophile audiophile is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 27
if then statements with two conditions...?

Is it possible to setup two conditions for an if then statement in a pbash script?

For example, depending on the text value of a variable I parse out of an xml file, I want to assign it a numerical values.

Example:

Code:
if [ "$VAR" = "Upper" ]; then
VAR="25"
fi

if [ "$VAR" = "Lower" ]; then
VAR="25"
fi
Can these two statements be replaced with a single one?
  #2 (permalink)  
Old 09-19-2008
manosubsulo manosubsulo is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 87
Code:
if [ "$VAR" = "Upper" -o "$VAR" = "Lower" ]
VAR="25"
fi
here -o represents logical or
  #3 (permalink)  
Old 09-19-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
What's "pbash"?

Code:
if [ "$VAR" = "Upper" ] || [ "$VAR" = "Lower" ]; then
  VAR=25
fi
Modern POSIX shells have a richer set of conditionals using [[ conditions ]], or you can use case:

Code:
case $VAR in Upper|Lower) VAR=25;; esac
  #4 (permalink)  
Old 09-19-2008
audiophile audiophile is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 27
Quote:
Originally Posted by era View Post
What's "pbash"?
Typeo... just plain bash

Thanks as always for the great replies. These forums and the contributing members are terrific!
Sponsored Links
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 09:47 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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