设置Mercurial Hook的环境变量

时间:2022-05-30 22:43:10

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.

我试图调用一个shell脚本,从一个mercurial钩子在我们的服务器上设置一堆环境变量。当一个新的变更组进入时,shell脚本会被调用,但环境变量不会超过对shell脚本的调用。

My hgrc file on the respository looks like this:

我在存储库上的hgrc文件如下所示:


[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.

我可以看到shell脚本的输出,然后是env命令的输出,但是env命令不包含shell脚本设置的新环境变量。

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.

我已经验证了shell脚本在单独运行时工作正常,但是当在mercurial钩子的上下文中运行时,它没有正确设置环境。

Thank you guys for any help you can provide.

谢谢你们提供任何帮助。

1 个解决方案

#1


2  

Shell scripts can't modify their enviroment.

Shell脚本无法修改其环境。

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

脚本可能无法将变量导出回其父进程,shell或环境。正如我们在生物学中所学到的,子进程可以从父进程继承,但反之亦然

$ 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

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.

我想我可以在一个php脚本中设置一个变量,然后通过一个接一个地运行一个神奇地用另一个来完成它。

#1


2  

Shell scripts can't modify their enviroment.

Shell脚本无法修改其环境。

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

脚本可能无法将变量导出回其父进程,shell或环境。正如我们在生物学中所学到的,子进程可以从父进程继承,但反之亦然

$ 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

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.

我想我可以在一个php脚本中设置一个变量,然后通过一个接一个地运行一个神奇地用另一个来完成它。