How to check for null or empty string | 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 to check for null or empty string

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-19-2007
doer doer is offline
Registered User
 
Join Date: Jul 2007
Last Activity: 24 July 2007, 1:31 AM EDT
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
How to check for null or empty string

Hi,

I need to check for value not equal (<>) to 21 and not equal empty or null values.

Please modify this script


Code:
if [ $VALUE -ne "21" ]
then
    echo "$VALUE,$BSC_NAME,$BSC_ID" > $OUT_FILE/power_up.out
end if


TQ

Last edited by Yogesh Sawant; 10-19-2010 at 07:18 AM.. Reason: added code tags
Sponsored Links
    #2  
Old 07-19-2007
doer doer is offline
Registered User
 
Join Date: Jul 2007
Last Activity: 24 July 2007, 1:31 AM EDT
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
can anyone help?
Sponsored Links
    #3  
Old 07-19-2007
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
 
Join Date: Dec 2003
Last Activity: 13 May 2013, 9:02 AM EDT
Location: Melbourne, Australia
Posts: 2,185
Thanks: 3
Thanked 24 Times in 23 Posts
Please read our rules and refrain from bumping your posts.

Thanks,
ZB
    #4  
Old 07-19-2007
doer doer is offline
Registered User
 
Join Date: Jul 2007
Last Activity: 24 July 2007, 1:31 AM EDT
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by zazzybob View Post
Please read our rules and refrain from bumping your posts.

Thanks,
ZB
Sorry. Anyway i found the solution. Thank you so much for the help.
Sponsored Links
    #5  
Old 07-19-2007
Awadhesh's Avatar
Awadhesh Awadhesh is offline
Registered User
 
Join Date: Jul 2005
Last Activity: 7 July 2008, 9:23 AM EDT
Location: Delhi, India
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
You shuld post the solution to help other forum members having same type of problems in coming future......

Cheers,

Awadhesh
Sponsored Links
    #6  
Old 07-24-2007
doer doer is offline
Registered User
 
Join Date: Jul 2007
Last Activity: 24 July 2007, 1:31 AM EDT
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by doer View Post
Hi,

I need to check for value not equal (<>) to 21 and not equal empty or null values.

Please modify this script

if [ $VALUE -ne "21" ]
then
echo "$VALUE,$BSC_NAME,$BSC_ID" > $OUT_FILE/power_up.out
end if


TQ

Here's the solution


Code:
if [ ! -n "$VALUE" ]
    then
   VALUE="21"
fi


Code:
if [ $VALUE -ne "21" ]
then
echo "$VALUE,$BSC_NAME,$BSC_ID" > $OUT_FILE/power_up.out
end if


Last edited by Yogesh Sawant; 10-19-2010 at 07:20 AM.. Reason: added code tags
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
Insert string 'NULL' where there is a null value zilch Shell Programming and Scripting 8 05-27-2010 09:17 AM
Check to see if string var is empty nirnir26 UNIX for Dummies Questions & Answers 2 11-24-2009 09:47 AM
Table null is empty priyanka3006 Shell Programming and Scripting 3 04-21-2009 05:40 AM
Check for empty string rahman_riyaz Shell Programming and Scripting 12 01-24-2008 02:13 AM
check for not null string in file misenkiser Shell Programming and Scripting 6 10-23-2006 10:39 AM



All times are GMT -4. The time now is 11:05 PM.