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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
shell problem not working!!! :(( baku Shell Programming and Scripting 1 04-10-2008 05:20 AM
Shell script is not working... vishalpatel03 Shell Programming and Scripting 2 01-10-2008 02:19 PM
how to find in which shell i am working.. pineapple Shell Programming and Scripting 2 04-01-2007 07:56 PM
shell not working hytechpro Shell Programming and Scripting 0 01-24-2006 11:19 PM
bourne shell not working gillbates Shell Programming and Scripting 6 06-17-2004 01:22 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-07-2007
Registered User
 

Join Date: Oct 2007
Posts: 6
if -z not working in SH shell

Hello all,

Any idea how to check whether a variable holding null value or not. if -z option works fine in bash, where as it is not working in sh.

bash-3.00$ sh
$ TEST=
$ if [ -z $TEST ] ; then
> echo "Null"
> else
> echo "Not null"
> fi
sh: test: 0403-004 Specify a parameter with this command.
Not null
$

The test fails. The same works in bash.

bash-3.00$ TEST=
bash-3.00$ if [ -z $TEST ] ; then
> echo "Null"
> else
> echo "Not null"
> fi
Null
bash-3.00$

I need this testing working in sh. Please help.

Thanks,
Rijesh.
Reply With Quote
Forum Sponsor
  #2  
Old 11-07-2007
Registered User
 

Join Date: Nov 2007
Posts: 23
$ if [ -z $TEST ] ; then


TRY this
$ if [ ! -n $TEST ] ; then
Reply With Quote
  #3  
Old 11-07-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
try

Code:
if test -z "$TEST"
then
   ...
fi
or

Code:
if [ -z "$TEST" ]
then
   ...
fi
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:23 AM.


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 Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0