我正在运行一个命令来查找目录中的所有make文件并运行make build
。
我想让xargs
在第一个失败的make build
上停止。
这是我到目前为止的命令。
$ find . -name "Makefile" | xargs dirname | xargs -I {} make -C {} build
问题是,即使在xargs
失败之后,make build
也会继续运行。当我检查最终的状态代码时,我看到的是。
$ echo $?
123
当我查看手册页时。上面是这么写的。
123 if any invocation of the command exited with status 1-125
这是有道理的,因为make build
s中的一些人在退出1点什么的时候失败了。
有办法让xargs
在第一个make build
错误时停止吗?
发布于 2020-03-05 03:18:10
XARGS(1):如果存在状态为255的命令调用,xargs将立即停止,而无需读取任何进一步的输入。
可以使用子subshell返回255
:
find . -name "Makefile" | xargs dirname | \
xargs -I {} sh -c 'make -C "$1" build || exit 255' sh {}
https://unix.stackexchange.com/questions/571215
复制相似问题