This is the content of makefile:
all:
export name="foo"
./s.sh
This is the content of s.sh:
echo "Name is:"
echo $name
Running make all will have this output:
export name="foo"
./s.sh
Name is:
How can I access the exported variable in my shell script?
CodePudding user response:
Each line of each recipe runs in its own shell. Thus, when each line finishes, that line's shell terminates, and it forgets all the variables that were set in it before it begins executing the next recipe line. You can catenate the lines to make them run in one shell as so:
all:
export name="foo"; \
./s.sh