linux shell 脚本中 避免文件已存在多次追加的情况
001、为了避免脚本多次执行,生成结果多次追加,可以在追加语句的前面增加清空语句避免多次追加
[root@pc1 test1]# ls a.sh [root@pc1 test1]# cat a.sh ## 测试脚本 #!/bin/bash > result.txt ## 或者使用 rm -f result.txt ## 在追加语句的前边增加清空语句 seq 2 >> result.txt [root@pc1 test1]# bash a.sh ## 测试脚本 [root@pc1 test1]# ls a.sh result.txt [root@pc1 test1]# cat result.txt ## 查看结果 1 2 [root@pc1 test1]# bash a.sh ## 再次执行 [root@pc1 test1]# cat result.txt ## 没有多次追加 1 2
。
分类:
linux shell
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
2021-03-06 python中LEGB原则
2021-03-06 python中内层函数可以调用外层函数的局部变量
2021-03-06 python中不能在外层函数以外调用内层函数
2021-03-06 python中函数后面的小括号的作用
2020-03-06 linux cut 命令的用法