本文介绍了rm -rf与-rm -rf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Makefile中,我读到:

In a Makefile, I read:

-rm -rf(而不是rm -rf). Makefile中行首的第一个-"是什么意思?

-rm -rf (instead of rm -rf). What does the first "-" mean at the beginning of the line in a Makefile ?

推荐答案

这意味着make本身将忽略rm中的任何错误代码.

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

makefile中,如果任何命令失败,则make进程本身将停止处理.通过为命令加上-前缀,可以通知make无论命令的结果如何,它都应继续处理规则.

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.

例如,makefile规则:

For example, the makefile rule:

clean:
    rm *.o
    rm *.a

如果rm *.o返回错误(例如,如果没有要删除的*.o文件),

删除*.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

将解决该特定问题.

另外:尽管在您的特定情况下可能不需要(因为-f标志似乎可以防止rm在文件不存在时返回错误),但这仍然是一种好习惯在makefile中明确标记该行-rm在某些情况下可能会返回 other 错误,这使您的意图更加清晰.

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.

这篇关于rm -rf与-rm -rf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 22:22