Question

I am trying to call a shell script that sets a bunch of environment variables on our server from a mercurial hook. The shell script gets called fine when a new changegroup comes in, but the environment variables aren't carrying over past the call to the shell script.

My hgrc file on the respository looks like this:

[hooks]
changegroup = shell_script
changegroup.env = env

I can see the output of the shell script, and then the output of the env command, but the env command doesn't include the new environment variables set by the shell script.

I have verified that the shell script works fine when run by itself but when run in the context of the mercurial hook it does not properly set the environment.

Was it helpful?

Solution

Shell scripts can't modify their enviroment.

http://tldp.org/LDP/abs/html/gotchas.html

A script may not export variables back to its parent process, the shell, or to the environment. Just as we learned in biology, a child process can inherit from a parent, but not vice versa

$ cat > eg.sh 
export FOO="bar";
^D
$ bash eg.sh 
$ echo $FOO; 

$

also, the problem is greater, as you have multiple calls of bash

bash 1 -> hg -> bash 2 ( shell script ) 
             -> bash 3 ( env call )

it would be like thinking I could set a variable in one php script and then magically get it with another simply by running one after the other.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top