wangdoc/bash-tutorial

grammar 中的 || 解释错了

bubao opened this issue · 1 comments

bubao commented
Command1 || Command2

上面命令的意思是,如果Command1命令运行失败,则继续运行Command2命令。
引用自 L155-L159

应该是:不管Command1命令运行失败与否,Command2命令都会执行。

$ mkdir foo || mkdir bar

上面例子中,只有mkdir foo命令执行失败(比如foo目录已经存在),才会继续执行mkdir bar命令。如果mkdir foo命令执行成功,就不会创建bar目录了
引用自 #L175-L179

应该是:即使mkdir foo命令执行失败,也会执行继续执行mkdir bar命令

例子

~/temp/mkdir-test 
➜ ls

~/temp/mkdir-test 
➜ mkdir foo             

~/temp/mkdir-test 
➜ ls
foo

~/temp/mkdir-test 
➜ mkdir foo || mkdir bar
mkdir: 无法创建目录 “foo”: 文件已存在

~/temp/mkdir-test 
➜ ls
bar  foo

command1 成功,command2 不会运行。