开发者

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

开发者 https://www.devze.com 2022-12-21 03:48 出处:网络
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.

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

精彩评论

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