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
"test: argument expected" error mvalonso UNIX for Dummies Questions & Answers 7 10-17-2008 08:16 AM
test: argument expected lalelle Shell Programming and Scripting 10 02-12-2008 04:24 AM
test: argument expected unitipon Shell Programming and Scripting 7 05-12-2007 11:54 AM
test: argument expected andy202 Shell Programming and Scripting 5 01-09-2007 08:06 AM
ERROR-> test: argument expected , what does it mean? tan102938 Shell Programming and Scripting 4 09-21-2006 08:20 PM

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

Join Date: Jul 2006
Posts: 31
Facing test: argument expected ERROR

Hi All,

When i run the below code :

v_shortfield = ""

if [ $v_shortfield = "" ] ; then
echo "ravi"
else
echo "kumar"
fi


i am getting output as :

sam.ksh[3]: test: argument expected
kumar


Why i am getting error test:argument expected
and why i am not getting output as "ravi"

How to check the value of a string, especially if it is empty.
I am facing this problem in my project.
Requesting for quick response.

Regards,
Ravi Kumar Garlapati
Reply With Quote
Forum Sponsor
  #2  
Old 07-20-2006
reborg's Avatar
Administrator
 

Join Date: Mar 2005
Location: Ireland
Posts: 3,638
Code:
if [ -z $v_shortfield  ] ; then
Reply With Quote
  #3  
Old 07-20-2006
Registered User
 

Join Date: Jul 2006
Posts: 31
Hi reborg,

What is the opposit for the below line :

if [ -z $v_shortfield ] ; then

i mean
if [ $v_shortfield != "" ]; then

how to write this in shell script ??

Please help me out.

Regards,
Ravi Kumar Garlapati

Last edited by rkrgarlapati; 07-20-2006 at 05:23 AM.
Reply With Quote
  #4  
Old 07-20-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,698
This is your original script.

Code:
v_shortfield = ""

if [ $v_shortfield = "" ] ; then
echo "ravi"
else
echo "kumar"
fi
Drop the space in the line v_shortfield = ""

It should become

Code:
v_shortfield=""

if [ -z $v_shortfield  ] ; then
echo "ravi"
else
echo "kumar"
fi
Reply With Quote
  #5  
Old 07-20-2006
reborg's Avatar
Administrator
 

Join Date: Mar 2005
Location: Ireland
Posts: 3,638
if [ ! -z $v_shortfield ]

or

if [ -n $v_shortfield ]
Reply With Quote
  #6  
Old 07-20-2006
Registered User
 

Join Date: Jul 2006
Posts: 31
How to use NOT EQUAL TO in Shell script

Hi reborg,

What is the opposit for the below line :

if [ -z $v_shortfield ] ; then

i mean
if [ $v_shortfield != "" ]; then

my second question is how to use Logical OR operator for Strings values ?

how to write this in shell script ??

Please help me out.

Regards,
Ravi Kumar Garlapati
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 11:12 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 Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0