Makefile:如何将命令的输出和退出代码分配给变量? [英] Makefile: How to assign a command's output and exit code to a variable?

查看:64
本文介绍了Makefile:如何将命令的输出和退出代码分配给变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种获取命令的输出和退出代码到makefile中变量的方法.

I am searching for a way to get the output and the exit code of a command to variables in a makefile.

基本上我想要这个:(bash)

Basicly I want this: (bash)

output=$(whoami)
returnval=$?
echo "OUT:"
echo $output
echo "RET:"
echo $returnval

放入makefile中

to be in a makefile

注意:应该在规则部分中起作用

note: should work in a rule section

谢谢

已解决

$(eval OUTPUT_RC="$(shell whoami;echo $$?)")
$(eval OUTPUT="$(shell echo $(OUTPUT_RC) | sed -e "s/^\(.*\)\(.\{2\}\)$$/\1/")")
$(eval RC="$(shell echo $(OUTPUT_RC) | sed -e "s/^.*\(.\)$$/\1/")")
echo $(OUTPUT)
echo $(RC)

推荐答案

如果仍然要使用 eval ,请使其打印可以直接 eval 的内容.

If you are going to use eval anyway, make it print things you can eval directly.

$(eval $(shell echo OUTPUT_RC=`whoami`; echo $$?))
OUTPUT=$(word 1,$(OUTPUT_RC))
RC=$(word 2,$(OUTPUT_RC))

这篇关于Makefile:如何将命令的输出和退出代码分配给变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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