0

(Related to Shell script to export environment variables in make)

I want to use a shell script to create some variables that make can later use. I thought I could just source the script:

target:
  . myscript
  echo ${FOO}   # FOO is exported in myscript

but this doesn't seem to work. Is there a way to do this?

3 Answers 3

1

How abt using an include directive instead. Put the variables defs in a separate makefile instead of a shell script.

Sign up to request clarification or add additional context in comments.

Comments

1

Using an include directive to set a target-specific variable might be the closest thing to what you're asking for.

Comments

0

This will work, but not quite the way you have it. make invokes a new shell for each line, so in the example you give, echo ${FOO} is in a new shell. You could simply do:

target:
  . myscript; \
  echo $${FOO}

note that you need two '$' signs on the $${FOO}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.