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

。

浙公网安备 33010602011771号