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

前端 未结 12 2166
心在旅途
心在旅途 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
    慢半拍i (楼主)
    2020-12-02 07:52

    The answers like the one from @mark-wilkins using \ to continue lines and ; to terminate them in the shell or like the ones from @kenorb changing this to one line are good and will fix this problem.

    there's a simpler answer to the original problem (as @alexey-polonsky pointed out). Use the -f flag to rm so that it won't trigger an error

    rm -f myApp
    

    this is simpler, faster and more reliable. Just be careful not to end up with a slash and an empty variable

    rm -f /$(myAppPath) #NEVER DO THIS

    you might end up deleting your system.

提交回复
热议问题