#!/bin/bash
status=" "
# Comparison 1: without error
echo "-----Comparison 1-----"
if [ ! $status = "success" ]
then echo 'Error: status was not success but: ' $status
else
echo "The status is success."
fi
echo "-----Comparison 2-----"
# Comparison 2: with error message but still shows success
if [ $status != "success" ]
then echo 'Error: status was not success but: ' $status
else
echo "The status is success."
fi
echo "-----Comparison 3-----"
# Comparison 3: Correct result after quoting status
if [ ! "$status" == "success" ]
then echo 'Error: status was not success but: ' $status
else
echo "The status is success."
fi
echo "-----Comparison 4-----"
# Comparison 4: Correct result after quoting status
if [ "$status" != "success" ]
then echo 'Error: status was not success but: ' $status
else
echo "The status is success."
fi
-----Comparison 1-----
The status is success.
-----Comparison 2-----
./test2.sh: line 14: [: !=: unary operator expected
The status is success.
-----Comparison 3-----
Error: status was not success but:
-----Comparison 4-----
Error: status was not success but:
其他问题
为什么会产生
"The status is success."
在里面
Comparison 2
语法错误之后?if语句中的语法错误如何影响if语句的计算结果?