我是shell脚本的新手。我想以特定的顺序调用Shell脚本中的make文件列表。对于每个makefile,我想得到结果(make表示成功或失败)。如果有任何错误,我想停止脚本执行。如果成功,我必须运行下一个makefile。
发布于 2013-06-14 15:00:29
一种常见的习惯用法是使用set -e创建一个shell脚本;这将导致脚本在出现第一个错误时退出。
#!/bin/sh
set -e
make -f Makefile1
make -f Makefile2
:如果您需要对整个脚本进行更多的控制,则可以删除set -e,并在make失败时显式退出:
make -f Makefile1 || exit
make -f Makefile2 || exit为了减少代码重复,创建一个循环:
for f in Makefile1 Makefile2; do
make -f "$f" || exit
done为了明确起见,||中的"or“和”&&“和”“连接词是
if make -f Makefile1; then
: "and" part
else
: "or" part
fi最后,您所描述的行为听起来与Make本身的行为完全相同。也许顶级Makefile实际上是适合您的场景的解决方案?
.PHONY: all
all:
$(MAKE) -f Makefile1
$(MAKE) -f Makefile2发布于 2013-06-14 14:50:30
make -f makefile1
make -f makefile2按顺序运行make files
保存每个makefile的输出
make -f makefile1 >> output1
make -f makefile2 >> output2检查每个make文件后的结果
make -f makefile1 >> output1在此行脚本之后使用
echo $? this in combination with if. if echo$? result zero then your make success so if echo$? result zero then run next file other wise exithttps://stackoverflow.com/questions/17102354
复制相似问题