How do I check if file exists in Makefile so I can delete it?

前端 未结 12 2111
心在旅途
心在旅途 2020-12-02 07:40

In the clean section of my Makefile I am trying to check if the file exists before deleting permanently. I use this code but I receive errors.

What\'s w

12条回答
  •  -上瘾入骨i
    2020-12-02 08:10

    One line solution:

       [ -f ./myfile ] && echo exists
    

    One line solution with error action:

       [ -f ./myfile ] && echo exists || echo not exists
    

    Example used in my make clean directives:

    clean:
        @[ -f ./myfile ] && rm myfile || true
    

    And make clean always works without any error messages!

提交回复
热议问题