我正在使用下面的 shell 脚本进行测试:
#!/bin/ksh -x
instance=`echo $1 | cut -d= -f2`
if [ $instance == "ALL" ]
then
echo "strings matched \n"
fi
它在 if 条件下给出了这个错误:
: ==: unknown test operator
==
真的不是正确的语法吗?
我在命令行上运行如下
test_lsn_2 INSTANCE=ALL
有人可以提出解决方案吗? 谢谢。
最佳答案
要比较字符串,您需要单个 =,而不是 double 。如果字符串为空,您应该将其放在双引号中:
if [ "$instance" = "ALL" ]
then
echo "strings matched \n"
fi
关于bash - 在 ksh 中比较字符串是否相等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1660507/