How can find Null value in If condition | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

How can find Null value in If condition

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-17-2007
koti_rama koti_rama is offline
Registered User
 
Join Date: Jun 2007
Last Activity: 26 November 2012, 10:02 AM EST
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
How can find Null value in If condition

Hi,
i wrote If Conditions in my script, it's returns null and some values.
but i am unable to find when Null value getting. bec we need modification according null vales.
pls help me on this.
Sponsored Links
    #2  
Old 07-17-2007
vino's Avatar
vino vino is offline Forum Advisor  
Supporter (in vino veritas)
 
Join Date: Feb 2005
Last Activity: 9 April 2013, 8:19 AM EDT
Location: Sydney, Down Under
Posts: 2,847
Thanks: 0
Thanked 12 Times in 12 Posts
NULL strings would translate to a string of length zero.

You could do this to check for the NULL'ness of a string.


Code:
if [ ! -n "$VARIABLE" ] ; then
  echo "VARIABLE is empty"
fi ;

or


Code:
if [ -z "$VARIABLE" ] ; then
  echo "VARIABLE is empty"
fi ;

See man test to see the description of the flags -n and -z
Sponsored Links
    #3  
Old 07-17-2007
srikanthus2002's Avatar
srikanthus2002 srikanthus2002 is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 14 October 2011, 3:22 PM EDT
Location: Can u guess...!
Posts: 161
Thanks: 0
Thanked 0 Times in 0 Posts

Code:
if [ "x $value" == "x """ ]
#if [ ! -n "$value" ]
then
        echo "empty"
else
        echo "Not empty"
fi

try it out..
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to find null column ken002 Shell Programming and Scripting 5 11-22-2010 01:41 AM
Using /dev/null with grep and find gaurav_s UNIX for Dummies Questions & Answers 0 07-27-2008 12:38 PM
Linux shell Script not null checking IF condition kaushys UNIX for Dummies Questions & Answers 3 07-02-2008 06:54 AM
How to compare null and space using single if condition jayakumarrt UNIX for Dummies Questions & Answers 3 05-16-2008 06:13 AM
Find files which contain a null character Bab00shka UNIX for Dummies Questions & Answers 5 12-16-2005 10:41 AM



All times are GMT -4. The time now is 07:40 PM.