如何忽略MV错误? [英] How to ignore mv error?

查看:592
本文介绍了如何忽略MV错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个Makefile,它将输出文件(foo.o)移动到另一个目录(baz).

I'm making a Makefile that moves an output file (foo.o) to a different directory (baz).

输出文件根据需要移动到目录.但是,如果再次输入make时make不会重新编译输出文件,则mv尝试将不存在的空文件移动到目录baz时会出错.

The output file moves as desired to the directory. However since make won't recompile the output file if I type make again, mv gets an error when it tries to move the non-existent empty file to the directory baz.

这就是我在所有编译后在规则make all中定义的内容:

So this is what I have defined in my rule make all after all compilation:

-test -e "foo.o" || mv -f foo.o ../baz

不幸的是,我仍然遇到错误.

Unfortunately, I'm still getting errors.

推荐答案

+@[ -d $(dir $@) ] || mkdir -p $(dir $@)

是我用来静默创建文件夹(如果它不存在)的方法.对于您的问题,这样的事情应该起作用

is what I use to silently create a folder if it does not exist. For your problem something like this should work

-@[ -e "foo.o" ] && mv -f foo.o ../baz

这篇关于如何忽略MV错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆