如果分配给变量的shell命令失败,如何使GNU Make失败? [英] How to make GNU Make fail if a shell command assigned to a variable failed?

查看:72
本文介绍了如果分配给变量的shell命令失败,如何使GNU Make失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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屋!

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