Makefile 坑
使用Makefile 定义变量,发现在shell中执行正常,但写到Makefile不执行。
# echo `pwd`
# /data/generate-alpha-v1.0.2 想取的 -alpha-v1.0.2
PWD_RESULT=$(echo `pwd` | sed -E 's/\/generate(.*)$/\1/')
报错 ,执行出来结果是\1
解决办法
里面存在两个错误
- sed 里面的表达式没有转义,$ 结尾应该写 $$
- 直接当做shell里面使用,$(echo
pwd
) 应该写成 $(shell echopwd
)
PWD_RESULT=$(shell echo `pwd` | sed -E 's/\/generate(.*)$$/\1/')
官方文档
https://makefiletutorial.com/#automatic-variables