Tuesday, June 12, 2012

Shell scripting issue in solaris10

hi frnds, I need help with my shell script. I wrote a script in shell in solaris 10 but when I run this script it gives error. How to remove this error. 

test: argument expected 




Hi, 

it is syntax error for test subcommand (probably). If true, then it is 
NOT related to Solarix. May we see script, please? 
Hi, 

You need to make sure that all of the variables that are tested within 
your script are initialised properly, and if a null value is acceptable, 
that the test is against a quoted variable eg.... 
X="" 

if [ $X = 1 ]; then 
do_something 
fi 

then this interprets as :- 

if [ = 1 ]; then..... 

Which is not syntactically correct. 

What you should do is ensure that all variable parameters that are 
subject to test are quoted, like so:- 

if [ "$X" = 1 ]; then...... 

Hence if X is null, then the evaluation becomes 

if [ "" = 1 ]; then..... 

which is syntactically correct, however I must caveat that if you want X 
to never be null when evaluated, it would be prudent to make a prior 
"is-it-null" check such as 

if [ -z "$X" ]; then ( or..... if [ ! -n "$X" ]; then.......) 
you might put your checks inside double quotes, both for the value and 
around the variable. If the variable is empty, it will return that error 
message. you might also preset the variable before attempting to use it the 
first time, to some value that allows you to start processing in your loop.
yes thanks for reply and my problem has now been resolved. I was wrote in 
script 


numb=`echo $text|sed -e 's#:.*$##g'` 
if [ $numb -gt 99 ] 

instead of : 

numb=`echo $text|sed -e 's#:.*$##g'` 
if [ ${numb:-1} -gt 99 ] 
We do a lot of scripting in sol10. Suspect you have a syntax error, usually related to a variable not being checked or the wrong qualifier (== vs -lt), etc.
it would help if you can put some sample code in order for us t be able to see why it is throwing that error. But it looks like your test argument is not complete.
just guess I bet you have a variable that is not double qouted 
in an if block that happens to be unset. Of course with the 
non-existent info you provided that is just a guess.
  If you put the line 'set -u' at the front of your script it will abort with an error message whenever you try to use a variable that is un-defined. In this case it might have been more obvious what the problem is.  


0 comments:

Post a Comment

 
Design by BABU | Dedicated to grandfather | welcome to BABU-UNIX-FORUM