我遗漏了关于bash的if构造/运算符或字符串比较的基本
内容.
请考虑以下脚本:
#!/bin/bash
baseSystem="testdir1"
testme="NA"
if [ "$baseSystem"=="$testme" ]; then
echo "In error case"
fi
if [ "$baseSystem"!="$testme" ]; then
echo "In error case"
fi
我明白了:
In error case
In error case
因此它进入每个案例,即使它们应该是互相排斥的.
任何帮助表示赞赏.
bash碰巧对空间有点特别.
在运算符周围添加空格:
if [ "$baseSystem" == "$testme" ]; then
...
if [ "$baseSystem" != "$testme" ]; then
以下不相同:
[ "$a"="$b" ]
[ "$a" = "$b" ]
你的第一次测试基本上与说“[testdir1 == NA”]相同;那将永远是真的.