Aabha Geed
Aabha Geed

Reputation: 49

How to export or set a make variable from a shell file

I am running a shell script from make environment

I execute the script with input parameters as make variables:

/shell_script.sh  $(make_var1) $(make_var2)

I process these variables in shell. I want to assign the result from a shell command to the make variable and export back to shell.

make_var=shell_command

How can I do this?

Upvotes: 0

Views: 742

Answers (1)

gauteh
gauteh

Reputation: 17205

It is not trivial to change the parent environment of a shell-script, one approach is to echo the export statements and source the output of the script in your parent environment:

...
echo "export make_var1=${make_var1}"
...

and when you launch your script do it using eval:

eval $(./shell_script.sh $make_var1 $make_var2)

this is the approach taken by for example ssh-agent.

A second option is to source the script, in that case the script will be run line-by-line in the current shell:

 . shell-script.sh

any export statements in the script will be run in the current shell.

Upvotes: 1

Related Questions