The UNIX and Linux Forums  


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 10:33 AM
problem with if, while, for conditions kittusri9 Shell Programming and Scripting 3 04-24-2008 10:15 AM
multiple conditions in if/then grandtheftander UNIX for Dummies Questions & Answers 4 07-21-2006 02: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 05:46 PM

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

Join Date: Sep 2006
Posts: 37
Quote:
Originally Posted by cfajohnson

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
THis is exactly what i was looking for. could you explain this please???
  #2 (permalink)  
Old 05-03-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
THis is exactly what i was looking for. could you explain this please???


First example:

: -- a command that does nothing but evaluate its arguments.

${XXXX:?} -- Bourne-shell parameter expansion; exits with an error if the variable is unset or empty.

${YYYYY:?} ${TTTT:?} ${NNNN:?} ${QQQQ:?} -- Ditto
Second example:

[b]${XXXX:+A} -- Bourne-shell parameter expansion that replaces the variable with A if it is set and not null.

var -- will contain AAAAA (i.e., have a length of 5) if all the variables are set and not null. If any are unset or null, the length of $var will be less than 5.

${#var} -- POSIX parameter expansion that gives the number of characters in the variable.
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 04:10 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