首页  

Linux Shell 多个命令中的分号(;) && ||     所属分类 shell 浏览量 561
让多条命令按顺序执行
;   命令1 ; 命令2	   
多条命令顺序执行,命令之间没有任何逻辑关系

&&	命令1 && 命令2	
如果命令1正确执行($?=0),则命令2才会执行
如果命令1执行不正确($?≠0),则命令2不会执行


||  命令1 || 命令2	
如果命令1执行不正确($?≠0),则命令2才会执行
如果命令1正确执行($?=0),则命令2不会执行


rm xxx.txt rm: xxx.txt: No such file or directory rm xxx.txt ; echo "hello" rm: xxx.txt: No such file or directory hello
rm xxx.txt rm: xxx.txt: No such file or directory rm xxx.txt && echo "hello" rm: xxx.txt: No such file or directory
touch xxx.txt rm xxx.txt && echo "hello" hello
rm xxx.txt rm: xxx.txt: No such file or directory rm xxx.txt || echo "hello" rm: xxx.txt: No such file or directory hello
touch xxx.txt rm xxx.txt || echo "hello"

上一篇     下一篇
c++ 标准输入输出

using namespace std 与 using std::cout

c c++ 网络库

Linux echo输出彩色字符串

C/C++预编译指令

C C++ 宏定义 # 与 ##