我用Makefile写的
define deploy_meta
$(shell git log -n 2 --oneline | awk '{print "commit"NR ": " $0}')
commit: nogit-$(timestamp)
tag: nogit-$(timestamp)
deployed-from: $(shell hostname)
deployed-by: $(USER)
deploy-date: $(shell date -u '+%Y%m%d%H%M%S')
endef但如果给了我
$cat .deploy
commit1: commit2:
commit: nogit-1669806282
tag: nogit-1669806282
...命令本身
git log -n 2 --oneline | awk '{print "commit"NR ": " $0}'工作良好,并给出两行。很明显,这让人感觉到了,因为它打印了两个"commit#“字。但它不打印内容。为什么?
发布于 2022-11-30 14:52:01
主要的问题很简单:让$0在这里扩展(什么都不做)。你需要$$0。
如果你想要两行,$(shell) is part of your problem here
--
shell函数提供了与大多数shell中提供的反引号('`')相同的工具:它确实命令扩展。这意味着它接受一个shell命令作为参数,并扩展到命令的输出。make对结果所做的唯一处理是将每个换行符(或回车/换行符对)转换为单个空格。如果有一个尾随(回车和)换行符,它将简单地被删除。
(强调我的)。您需要一种完全不同的方法,例如,使用$(shell)生成一个文件,然后使用include生成该文件。
https://stackoverflow.com/questions/74626811
复制相似问题