Make:命令失败后如何继续?
命令$ make all
给出诸如rm:cannotremove'.lambda':Nosuchfileordirectory
之类的错误,因此它停止。我希望它忽略 rm-not-found-errors。我怎样才能强制?
生成文件
all:
make clean
make .lambda
make .lambda_t
make .activity
make .activity_t_lambda
clean:
rm .lambda .lambda_t .activity .activity_t_lambda
.lambda:
awk '{printf "%.4f \n", log(2)/log(2.71828183)/$$1}' t_year > .lambda
.lambda_t:
paste .lambda t_year > .lambda_t
.activity:
awk '{printf "%.4f \n", $$1*2.71828183^(-$$1*$$2)}' .lambda_t > .activity
.activity_t_lambda:
paste .activity t_year .lambda | sed -e 's@\t@\t\&\t@g' -e 's@$$@\t\\\\@g' | tee > .activity_t_lambda > ../RESULTS/currentActivity.tex
The command $ make all
gives errors such as rm: cannot remove '.lambda': No such file or directory
so it stops. I want it to ignore the rm-not-found-errors. How can I force-make?
Makefile
all:
make clean
make .lambda
make .lambda_t
make .activity
make .activity_t_lambda
clean:
rm .lambda .lambda_t .activity .activity_t_lambda
.lambda:
awk '{printf "%.4f \n", log(2)/log(2.71828183)/$1}' t_year > .lambda
.lambda_t:
paste .lambda t_year > .lambda_t
.activity:
awk '{printf "%.4f \n", $1*2.71828183^(-$1*$2)}' .lambda_t > .activity
.activity_t_lambda:
paste .activity t_year .lambda | sed -e 's@\t@\t\&\t@g' -e 's@$@\t\\\\@g' | tee > .activity_t_lambda > ../RESULTS/currentActivity.tex
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
尝试使用
-i
标志(或--ignore-errors
)。 文档似乎提出了一种更强大的方法来实现这一目标,通过道路:所有示例均使用
rm
,但适用于您需要忽略错误的任何其他命令(即mkdir
)。Try the
-i
flag (or--ignore-errors
). The documentation seems to suggest a more robust way to achieve this, by the way:All examples are with
rm
, but are applicable to any other command you need to ignore errors from (i.e.mkdir
).我认为
make -k
(或 gnumake 上的--keep-going
)会满足您的要求。您确实应该找到失败的 del 或 rm 行,并向其添加
-f
以防止该错误发生在其他人身上。make -k
(or--keep-going
on gnumake) will do what you are asking for, I think.You really ought to find the del or rm line that is failing and add a
-f
to it to keep that error from happening to others though.通过使用
true
命令在管道后面阻止rm
的返回码来成功返回,该命令始终返回0
(成功)。请注意,
||
运算符在 shell 中表示 OR。这意味着您基本上执行的是command OR true
,它将始终返回true
,因此任何使用此命令的脚本都将继续。Return successfully by blocking
rm
's returncode behind a pipe with thetrue
command, which always returns0
(success).Note that the
||
operator means OR in shell. This means that you're basically doingcommand OR true
which will always returntrue
, so any script using this will continue.将 clean 更改为
I.e.不提示删除;如果文件不存在,请不要抱怨。
Change clean to
I.e. don't prompt for remove; don't complain if file doesn't exist.
要让 make 实际上忽略单行上的错误,您只需在其后加上
; 即可。 true
,将返回值设置为0。例如:这会将stderr输出重定向为null,并在命令后面加上true(它总是返回0,使make相信命令成功,无论实际发生了什么),允许程序流程继续进行。
To get make to actually ignore errors on a single line, you can simply suffix it with
; true
, setting the return value to 0. For example:This will redirect stderr output to null, and follow the command with true (which always returns 0, causing make to believe the command succeeded regardless of what actually happened), allowing program flow to continue.
在
rm
命令中添加-f
选项。Put an
-f
option in yourrm
command.使用
-
似乎是处理这种情况的正确方法,因为它可以忽略特定命令的错误,但不能忽略所有错误。您可以通过以下链接找到更多信息。
Usage of
-
seems to be a proper way of handling such situations as it can ignore the error of a specific command, but not all errors.You can find more information by the following link.
更改您的
clean
,这样rm
就不会抱怨:Change your
clean
sorm
will not complain: