Using makefile variables in shell script

2019-04-14 19:15发布

I've a makefile where all the environment variables are defined (top directory) and I want to use some of these variables in a shell script present at innermost level.

How should I access those variables in the script? Do I need to IPC for passing the variables or is there any other method to do the same?

2条回答
等我变得足够好
2楼-- · 2019-04-14 19:20

If make exports the variables, you can use them right away (but note that changes to shell variables will not change the make variables). If you use GNU make, you can use the export directive.

If make does not export the variable, you can use the shell's one-shot assignment, like in

UNEXPORTED_VAR = foo
all:
     UNEXPORTED_VAR='$(UNEXPORTED_VAR)' OTHERVAR='$(OTHERVAR)' script.sh
查看更多
狗以群分
3楼-- · 2019-04-14 19:20

Like Jens said is correct, export make variables can be used. But his solution is not working for me. So what you can also do is just export them in the makefile:

export UNEXPORTED_VAR
查看更多
登录 后发表回答