与 Bash 中输出的字符串比较
string comparison with output in Bash
我有一个简单的脚本,效果很好(并打印 hello
)
variable=false
if [ "$variable" = "false" ]; then
echo hello
fi
但是,这不起作用(并且不打印 hello
)
variable=$(source script.sh \
| awk -F":" '/maintenanceMode\>/ { print i }' \
| sed 's/,//g'
)
echo $variable # prints `false`, as expected
if [ "$variable" = "false" ]; then
echo hello
fi
我错过了什么?
去除变量中的空格。
$variable=`echo $variable | xargs`
我有一个简单的脚本,效果很好(并打印 hello
)
variable=false
if [ "$variable" = "false" ]; then
echo hello
fi
但是,这不起作用(并且不打印 hello
)
variable=$(source script.sh \
| awk -F":" '/maintenanceMode\>/ { print i }' \
| sed 's/,//g'
)
echo $variable # prints `false`, as expected
if [ "$variable" = "false" ]; then
echo hello
fi
我错过了什么?
去除变量中的空格。
$variable=`echo $variable | xargs`