0
dummy$ cat Makefile 
.PHONY: env

env:
        export v1="def"
        export v2="abc"

dummy$ make env
export v1="def"
export v2="abc"
dummy$ 
dummy$ echo $v1

dummy$ echo $v2

dummy$ 

Why v1 does not display value?

overexchange
  • 15,768
  • 30
  • 152
  • 347
  • I don't think it's possible. – HolyBlackCat Feb 25 '22 at 17:45
  • @HolyBlackCat Can't we export variables through Makefile? – overexchange Feb 25 '22 at 17:46
  • 3
    I don't think a child process can ever directly change the parent's environment variables. Maybe you could get hacky with something like `source $(make env)` but at that point I'd see little value in using a makefile at all. – Stephen Newell Feb 25 '22 at 17:48
  • 6
    The term *export* means, send this new environment variable to all sub-processes created by this process. It does not mean, send this new environment variable to parent processes that created this process. The latter is impossible (it has nothing to do with make; you can't do it with any process). – MadScientist Feb 25 '22 at 17:50
  • https://stackoverflow.com/questions/23843106/how-to-set-child-process-environment-variable-in-makefile – GoinOff Feb 25 '22 at 18:26

0 Answers0