且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我的Perl脚本是否从“某处别”中获取环境变量?

更新时间:2023-12-04 21:54:10

好的,这是什么继续:



perl本身完全是一个红色的鲱鱼。



该脚本正在一个子shell中执行创建时,正在重新加载rc文件。这些rc文件正在吹除我在父shell中手动添加的环境变量,并附有引用副本。



我能够用一个简单的csh脚本来显示这个只是回应了这个环境。



取消选择我的rc文件(已经超过了这个),清除了神秘的替代品。


$ b $更新:证明这一点的测试是一个test.sh,它有一个简单的set命令。证明子shell没有正确地继承父环境。奇怪的是,当我将父级交互式shell切换到ksh时,环境开始正确继承。

On a Solaris box in a "mysterious production system" I'm running a Perl script that references an environment variable. No big deal.

The contents of that variable from the shell both pre- and post-execution are what I expect.

However, when reported by the script, it appears as though it's running in some other sub-shell which is clobbering my vars with different values for the duration of the script.

Unfortunately I really can't paste the code. I'm trying to get an atomic case, but I'm at my wit's end here.

Ok, here's what was going on:

perl itself was a red herring entirely.

The script was executing in a child shell which, when created, was re-loading rc files. Those rc files were blowing away the environment variables I had manually added during the parent shell with reference copies.

I was able to demonstrate this with a simple csh script that just echoed just echoed the environment.

De-wonkifying my rc files (which were overwrought with wonkitude) cleared up the mystical replacement.

UPDATE: The test that proved this was a "test.sh" that had a simple "set" command. It proved that the sub-shell wasn't inheriting the parent environment correctly. Oddly, when I switched my parent interactive shell to ksh, the environment began inheriting correctly.