开发者

I want to compare * as a literal by passin g it as command line argument

I am exceuting a shell script from windows machine through plink. I want to compare the "*" (passed as command line argument) to a literal in my script. Can anyone suggest me the way to comp开发者_如何学运维are * as a literal?. I have tried with all possible ways like including $1 in double quotes, single quotes, [].


It's expanded by the shell so you have to pass it to the script either in quotes or escaped:

echo '*'
echo "*"
echo \*


it should not be a problem, the script:

#! /bin/bash

if [[ "$1" == '*' ]]
then
  echo EQ
else
  echo NE
fi

The execution:

./aaa.bash '*'


You problem is that you need to quote the constant *, not the parameter that you are comparing it to.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜