Problems with "test"

i'm getting the following error when i run the shell script. Can you please help me out. :
compareReports.sh[17]: test: argument expected
compareReports.sh[17]: Difference: unknown test operator
compareReports.sh[17]: test: argument expected
compareReports.sh[17]: test: argument expected
compareReports.sh[20]: test: argument expected
compareReports.sh[20]: Difference: unknown test operator
compareReports.sh[20]: test: argument expected
compareReports.sh[20]: test: argument expected

this is the function in the script :

ftpFromProd() {
GET_CMD=""
while [ true ]
do
read line
if [ $? -ne 0 ];then
break
fi
if [ -z "$line" ] || [ `expr "$line" : "#"` -gt 0 ]
then
(this is the 17th line) continue
fi
fileName=`echo $line | sed -e 's/\*/\\\/g' -e "s@\*@\\\@g" -e "s@BATCHDIR@$tar_batchDir@g" -e "s/RUNDATE/$rd
ate/g"`
(this is th 20th line)echo "FileName->$fileName"
r_dir=`dirname $fileName`
echo "Dir->$r_dir"
file=`basename $fileName`
echo "file->$file"
l_dir="$opdir/$r_dir"
if [ ! -d $l_dir ]; then
mkdir -p $l_dir
fi
GET_CMD="$GET_CMD lcd $l_dir\n cd $r_dir\n mget $file\n"
done < $SCRIPTLOC/config_file.txt

ftp -in $hostName <<EOF
quote USER $userid
quote PASS $pwd
binary
`echo $GET_CMD`
quit
EOF

}

hi,
please don't crosspost your problems in various threads. new problem = new thread!

use -o in place of ||

Nope, that's not it, the use of || is correct (but the rest of the script hurts to look at, no offense)

I'm guessing the line numbers are off, can you run it with sh -x compareReports.sh to see where the errors are really coming from?

The error message indicates you have an unquoted variable with an unexpected value in it. You should actually probably put double quotes around all your variables regardless.

whenever you see errors like this, i.e. [17]: [20]:
This corresponds to the line number in the script, where the error happened, so your error might not be in that function but elsewhere, you didnt list the entire script so is hard to tell.
you can:

vi +17 scriptname
vi +20 scriptname
# to take you to either of those exact lines.

hi
i tried out sh -x compareReports.sh
i'm getting the following message
+ function usage {
compareReports.sh: function: not found
+ echo Usage: compareReports.sh [-s env1] -t env2 [-r rundate] [-o report directory] [-u userid ] [-p passwd] [-h hostname ] [-l script location]
Usage: compareReports.sh [-s env1] -t env2 [-r rundate] [-o report directory] [-u userid ] [-p passwd] [-h hostname ] [-l script location]
compareReports.sh: syntax error at line 6: `}' unexpected

i dont think there is any error.....

when i tried using these
vi +17 scriptname
vi +20 scriptname

they pointed to blank lines(because the 17th and the 20th lines are blank in the script)

Please help me out

If it says "function: not found" they it doesn't understand the function keyword. Take it out, it's not needed (and not part of Bourne syntax as per POSIX).

usage () {
  body of function goes here
}

yeah i tried out that and that error went off... :)thanks for that.... but still i'm getting the following msg wen i run the script
:confused:
compareReports.sh[17]: test: argument expected
compareReports.sh[17]: Difference: unknown test operator
compareReports.sh[17]: test: argument expected
compareReports.sh[17]: test: argument expected
compareReports.sh[20]: test: argument expected
compareReports.sh[20]: Difference: unknown test operator
compareReports.sh[20]: test: argument expected
compareReports.sh[20]: test: argument expected

Often, it means you have not quoted a variable properly. The command test is also known as [ (that's right, opening square bracket). Anywhere you see something like

if [ $variable -ne "foo" ]

... you want to add proper quoting, like

if [ "$variable" -ne "foo]

Ditto for where you have a literal "test" command, of course. See also UNIX Shell Quote and the responses people have posted earlier in this thread.

If you can't figure it out yourself, please post the code around lines 17 and 20, as it appears to contain a syntax error. "Difference" is probably the content of the unquoted or otherwise problematic variable, but of course, if you have a literal string "Difference" in your script then that, too, would be interesting to see.