我有这段代码:
if(("$op" == "q")); then
抛出这个错误:
l5p3.sh: line 10: ((: + == q: syntax error: operand expected (error token is "== q")
有什么问题吗?如何比较 $op 和字母 $q ?
最佳答案
(( ... ))
(用于算术表达式)可能不是您想要的。检查以下内容:
if (("asd" == "bla")); then
echo test
else
echo bah
fi
它在 Bash 中打印 test
并在像 dash
这样严格兼容 bourne 的 shell 中打印错误。
请尝试以下操作:
if [[ $op == q ]]; then
关于linux - bash:使用(( "$var"== "string"))进行比较的语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9881609/