The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Checking the Empty line in csv file sollins Shell Programming and Scripting 4 05-15-2008 04:48 AM
how to echo the file contents LINE BY LINE newbie168 Shell Programming and Scripting 4 02-22-2006 02:43 AM
if test for empty and non-existing file GNMIKE Shell Programming and Scripting 3 10-20-2005 11:51 PM
empty line YoYo Shell Programming and Scripting 4 09-21-2005 08:14 PM
printing an empty line in a file (perl) kfad Shell Programming and Scripting 3 05-07-2005 12:10 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-22-2008
Registered User
 

Join Date: Mar 2007
Posts: 31
What's wrong with this line: if ${TEST:?} ; then echo empty; fi

I want to print "empty" if $TEST is empty.

TEST=
if ${TEST:?} ; then echo empty; fi

But it doesn't work. What's wrong?
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-23-2008
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Code:
$ cat > foo.ksh
#!/bin/ksh
TEST=
FOO=${TEST:?empty}
$ chmod +x ./foo.ksh$ ./foo.ksh
./foo.ksh: line 3: TEST: empty
$ sed 's/^TEST=/TEST=something/' foo.ksh > foo2.ksh
$ chmod +x ./foo2.ksh
$ ./foo2.ksh
$
No need for the conditional structure, a simple variable assignment will do it.

Cheers,
ZB
Reply With Quote
  #3 (permalink)  
Old 02-23-2008
Moderator
 

Join Date: Dec 2003
Location: /dev/florida
Posts: 955
${TEST:?} will cause your script to exit immediately. If you want to exit more
gracefully or do some cleanup, the following method of testing for an null or
empty string may be more useful.

Code:
#!/usr/bin/ksh

TEST=

if [[ ! $TEST ]]
then
   echo "empty"
fi
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:02 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0