我的Perl脚本是否从“某处别”中获取环境变量? [英] Is my Perl script grabbing environment variables from "someplace else"?

查看:133
本文介绍了我的Perl脚本是否从“某处别”中获取环境变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在神秘生产系统的Solaris框中,我运行一个引用环境变量的Perl脚本。没有什么大不了的。



从预期和执行后的shell中的该变量的内容是我期望的。



但是,当脚本报告时,它似乎运行在其他一些子shell中,这个子shell在脚本的持续时间内使用不同的值来克隆我的var。



不幸的是,我真的无法粘贴代码。我想要得到一个原子的案例,但我在这里的机智结束。

解决方案

好的,这是什么继续:



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.

这篇关于我的Perl脚本是否从“某处别”中获取环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆