Bash if语句行为

我遗漏了关于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”]相同;那将永远是真的.

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...