小编acg*_*ant的帖子

为什么“if [ 0 ]”在bash脚本中执行“then”语句?

本指南说:

 An if/then construct tests whether the exit status of a list of commands is 0
Run Code Online (Sandbox Code Playgroud)

如果我0在 bash 中执行,它会说:

0: command not found
Run Code Online (Sandbox Code Playgroud)

所以它的退出状态不是 0,也[ 0 ]应该返回一个非零值的退出状态。但它实际上返回 0 退出状态,并if [ 0 ]执行then语句,而不是else语句。
谁能解释一下?

bash scripts

5
推荐指数
1
解决办法
3万
查看次数

标签 统计

bash ×1

scripts ×1