在Makefile中看到一个这样的命令,@set -e,这是什么作用

bigwater 2008-01-31 05:03:42
%.d: %.c
@set -e; rm -f $@; \
$(CC) -M $(CPPFLAGS) $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
...全文
1890 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
mymtom 2008-02-02
  • 打赏
  • 举报
回复
Use set -e
Every script you write should include set -e at the top. This tells bash that it should exit the script if any statement returns a non-true return value. The benefit of using -e is that it prevents errors snowballing into serious issues when they could have been caught earlier. Again, for readability you may want to use set -o errexit.

Using -e gives you error checking for free. If you forget to check something, bash will do it or you. Unfortunately it means you can't check $? as bash will never get to the checking code if it isn't zero. There are other constructs you could use:

commandif [ "$?"-ne 0]; then echo "command failed"; exit 1; fi
could be replaced with

command || { echo "command failed"; exit 1; }
or

if ! command; then echo "command failed"; exit 1; fi
What if you have a command that returns non-zero or you are not interested in its return value? You can use command || true, or if you have a longer section of code, you can turn off the error checking, but I recommend you use this sparingly.

set +ecommand1command2set -e
bigwater 2008-01-31
  • 打赏
  • 举报
回复 1
自己解决了。原来加了@表示makefile执行这条命令时不显示出来。

23,115

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧