linux 中 && 用法

 

001、

复制代码
[root@pc1 test2]# ls
test.sh
[root@pc1 test2]# cat test.sh      ## 测试程序
#!/bin/bash

seq 10 > a.txt

xxxxxx  && echo 20 done ; rm a.txt
[root@pc1 test2]# bash test.sh       ## a.txt被删除了,代码rm a.txt属于单独的代码块
test.sh: line 5: xxxxxx: command not found
[root@pc1 test2]# ls
test.sh
复制代码

 

002、修改程序

复制代码
[root@pc1 test2]# ls
test.sh
[root@pc1 test2]# cat test.sh         ## 测试程序
#!/bin/bash

seq 10 > a.txt

xxxxxx  && echo 20 done && rm a.txt
[root@pc1 test2]# bash test.sh    
test.sh: line 5: xxxxxx: command not found
[root@pc1 test2]# ls                  ## a.txt被保留,&&的作用是在上一个代码块执行成功的情况下,才执行下一个代码块
a.txt  test.sh
复制代码

 

posted @   小鲨鱼2018  阅读(94)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2022-09-21 普通用户调整vim编辑器配置
2022-09-21 如何解决vim 编辑器注释行后面字符开不清
2022-09-21 集群环境中使用sbatch提交命令测试
2022-09-21 conda中如何创建、查看、删除虚拟环境
2020-09-21 linux hedhat8 安装 java环境
点击右上角即可分享
微信分享提示