开发者

rm -rf versus -rm -rf

In a Makefile, I read:

-rm -rf (instead of rm -rf). What does the first "-" mean at the beginning of the line in a Makefil开发者_如何学Goe ?


It means that make itself will ignore any error code from rm.

In a makefile, if any command fails then the make process itself discontinues processing. By prefixing your commands with -, you notify make that it should continue processing rules no matter the outcome of the command.

For example, the makefile rule:

clean:
    rm *.o
    rm *.a

will not remove the *.a files if rm *.o returns an error (if, for example, there aren't any *.o files to delete). Using:

clean:
    -rm *.o
    -rm *.a

will fix that particular problem.


Aside: Although it's probably not needed in your specific case (since the -f flag appears to prevent rm from returning an error when the file does not exist), it's still good practice to mark the line explicitly in the makefile - rm may return other errors under certain circumstances and it makes your intent clear.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜