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
分类:
linux shell
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!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环境