0
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

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by k2k
0

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

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.