How to use Bash parameter substitution in a Makefile?

北城以北 提交于 2019-11-29 18:39:09

If you want the shell to expand the variable you have to use a shell variable, not a make variable. ${Foo/Bar/OK} is a make variable named literally Foo/Bar/OK.

If you want to use shell variable substitution you'll have to assign that value to a shell variable:

all:
        Foo='$(Foo)'; echo $${Foo/Bar/OK}

Note that we use the double-dollar $$ to escape the dollar sign so that make doesn't try to expand it.

I strongly recommend you don't add @ to your rules until you're sure they work. It's the single most common mistake I see; if people would just not use @ they could see the command make is invoking, and then they would better understand how make works.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!