小编Cha*_*esB的帖子

为什么我需要为 if 引用变量,而不是为 echo 引用?

我读过你需要双引号来扩展变量,例如

if [ -n "$test" ]; then echo '$test ok'; else echo '$test null'; fi
Run Code Online (Sandbox Code Playgroud)

将按预期工作,而

if [ -n $test ]; then echo '$test ok'; else echo '$test null'; fi
Run Code Online (Sandbox Code Playgroud)

总是会说$test ok即使$test为空。

但是为什么我们不需要引号echo $test呢?

shell quoting

29
推荐指数
2
解决办法
9765
查看次数

标签 统计

quoting ×1

shell ×1