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
How to giv two conditions in IF statement..?? RRVARMA Shell Programming and Scripting 6 04-25-2008 09:33 AM
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

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-02-2007
hitmansilentass hitmansilentass is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 37
reduce the or conditions

Hi ,

how can i reduce the or conditions:

if [[ -z $XXXX || -z $YYYYY || -z $TTTT || -z $NNNN || -z $QQQQ ]]; then

whatever

fi
  #2 (permalink)  
Old 05-02-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,715
Do you want to speed it up? Consider putting the likeliest cases on the left hand side of the if statement, if this is POSIX shell.

Otherwise, what are you trying to do?
  #3 (permalink)  
Old 05-02-2007
kahuna's Avatar
kahuna kahuna is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 149
How about?
Code:
case "+$XXXX+$YYYYY+$TTTT+$NNNN+$QQQQ+" in
 *++* ) whatever;;
esac
  #4 (permalink)  
Old 05-02-2007
ahmedwaseem2000 ahmedwaseem2000 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Bangalore
Posts: 219
Incorrect post, Moderators please delete this
  #5 (permalink)  
Old 05-02-2007
hitmansilentass hitmansilentass is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 37
Quote:
Originally Posted by jim mcnamara
Do you want to speed it up? Consider putting the likeliest cases on the left hand side of the if statement, if this is POSIX shell.

Otherwise, what are you trying to do?
I am trying to check if all the variables has been initialized or not. there are too many 'or' (||) conditions which i want to reduce so that it looks better
  #6 (permalink)  
Old 05-02-2007
kahuna's Avatar
kahuna kahuna is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 149
Quote:
Originally Posted by hitmansilentass
there are too many 'or' (||) conditions which i want to reduce so that it looks better
It's not clear what you mean by "looks better". Exactly what would "look better" look like? Assuming your variables do not contain whitespace, another alternative without || might be
Code:
if [[ `echo $XXXX $YYYYY $TTTT $NNNN $QQQQ |wc -w` -ne 5 ]]; then
whatever
fi
  #7 (permalink)  
Old 05-02-2007
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Quote:
Originally Posted by hitmansilentass
Hi ,

how can i reduce the or conditions:

if [[ -z $XXXX || -z $YYYYY || -z $TTTT || -z $NNNN || -z $QQQQ ]]; then

whatever

fi

To exit the script if any var is empty or unset:

Code:
: ${XXXX:?} ${YYYYY:?} ${TTTT:?} ${NNNN:?} ${QQQQ:?}
To execute something if any parameter is empty or unset:

Code:
var=${XXXX:+A}${YYYYY:+A}${TTTT:+A}${NNNN:+A}${QQQQ:+A}
if [ ${#var} -ne 5 ]; then
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:31 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