如果分配给变量的shell命令失败,如何使GNU Make失败? [英] How to make GNU Make fail if a shell command assigned to a variable failed?
问题描述
我有一个Make变量:
I have a Make variable:
PASSWORD:=$(shell vault read -field=password test/password)
如果未安装vault
,则make
将打印make: vault: Command not found
,但继续执行配方.如何使它失败并在表达式失败时停止执行?
If vault
is not installed, make
will print make: vault: Command not found
, but continue executing the recipe. How do I make it fail and stop execution if the expression fails?
推荐答案
In case you are intending to use a call
function, and want to abort at one central place (so that future users of GET_SECRET
do not forget to check e.g. .SHELLSTATUS
), I found this hack practical:
GET_SECRET = $(shell vault read -field=$(1) $(2) || { echo >&2 "Error reading field $(1) from vault path $(2), aborting"; kill $$PPID; })
父make
进程因shell
错误而被杀死.另请参阅 225542/how-to-make-a-failing- shell-command-interrupt-make 和 50958731/将shell输出分配给变量或退出终止makefile
The parent make
process is killed of shell
error. See also 225542/how-to-make-a-failing-shell-command-interrupt-make and 50958731/assign-shell-output-to-variable-or-exit-terminate-makefile
这篇关于如果分配给变量的shell命令失败,如何使GNU Make失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!