shell script to remove a file if it already exist

前端 未结 7 1095
面向向阳花
面向向阳花 2021-01-30 15:43

I am working on some stuff where I am storing data in a file. But each time I run the script it gets appended to the previous file.

I want help on how I can remove the f

7条回答
  •  既然无缘
    2021-01-30 15:58

    Something like this would work

    #!/bin/sh
    
    if [ -fe FILE ]
    then 
        rm FILE
    fi 
    

    -f checks if it's a regular file

    -e checks if the file exist

    Introduction to if for more information

    EDIT : -e used with -f is redundant, fo using -f alone should work too

提交回复
热议问题