Using makefile variables in shell script

前端 未结 2 494
梦毁少年i
梦毁少年i 2021-01-06 05:25

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.

相关标签:
2条回答
  • 2021-01-06 06:17

    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
    
    0 讨论(0)
  • 2021-01-06 06:25

    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
    
    0 讨论(0)
提交回复
热议问题