1 #!/bin/bash2 #3 [ e "/etc/passwd" ] || (echo 'No such file.';exit 1)4 if [ $? -eq 1 ]5 then6 exit7 fi8 echo "the file exists."9 exit 0第三行那个||怎么理解,是”或“吗?
1 回答

呼啦一阵风
TA贡献1802条经验 获得超6个赞
|| 为命令执行控制
语法格式如下:
command1 || command2 [|| command3 ...]
1、命令之间使用 || 连接,实现逻辑或的功能。
2、只有在 || 左边的命令返回假(命令返回值 $? == 1),|| 右边的命令才会被执行。这和 c 语言中的逻辑或语法功能相同,即实现短路逻辑或操作。
3、只要有一个命令返回真(命令返回值 $? == 0),后面的命令就不会被执行。
添加回答
举报
0/150
提交
取消