if [ "$1"="-s" -a -n "$2" ]      # if $1 is string "-s" and $2 is not null 
then 
     string="$2"                    # then string="$2"
else
     echo "error"
     exit 1
fi
echo $string

i expect: foo -not"-s" hi return "error"
however,, no matter what i type after the - , the test will return true. why is that?

i already tried para=`echo "$@"` ; set -- $para still not working properly

Hey there,

You just need to change the

"$1"="-s"

to

"$1" = "-s"

with space on both sides of the = operator and it works well :)

Best wishes,

Mike

Mike,
thanks again for the help. i am more experienced after all these misconceptions.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.