Error:--test: argument expected--Even though i give an argument.

Hi All,

I am running the script

VBoxManage list vms |sed 's/"//g' | cut -d " " -f1 > har1out.mytxt

result=`cat har1out.mytxt | grep $1'
echo $result
echo $1

{

if [ $result -eq $1 ]
then
echo pass
else
echo fail
fi

}

when i pass a argument which is present in the output file, it says Pass, but when i am giving a negative test says " test: argument expected"

Please help, am running it in solaris env. thank you.

change

if [ $result -eq $1 ]

to

if [ "$result" = "$1" ]

-eq only works for integers, and you can pass ant string as $1, You may also want to change your grep to

grep -F "$1"

. This -F lets you pass characters that don't get translated into a regular expression. Just a straight fixed pattern.

1 Like

Hi Jim,
Thank you, It works fine now.