Bash shell 在两行之间丢失环境变量
我有一个 bash 脚本,如下所示:
rvm use 1.8.7
rvm list
第一行是在我的 .bashrc 文件中加载的函数,它定义了一些环境变量。当执行第二行时,这些变量已被设置为其先前的值(设置值已丢失)。我在这里缺少什么?
在 ubuntu 盒子上运行。
I have a bash script as follows:
rvm use 1.8.7
rvm list
The first line is a function loaded within my .bashrc file that defines some enviroment variables. When executing the second line, those variables have been set to their previous values (the set values have been lost). What am I missing here?
Running on a ubuntu box.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正在创建一个子 shell,并在其中设置变量。当子 shell 退出时,更改将丢失。当
while
循环位于管道中时,通常会发生这种情况。如果没有看到该功能,就不可能比这更具体。A subshell is being created and the variables are set within it. When the subshell exits, the changes are lost. This often happens when a
while
loop is in a pipe. Without seeing the function it's impossible to be more specific than that.当您定义要供所有子 shell 使用的环境变量时,您需要在其前面添加导出前缀,如下所示:
export myvar =“some value”
我会检查rvm是否正确执行此操作
when you define environment variables that you want to make available to all subshells you need to prefix it with export like so:
export myvar="some value"
I would check that rvm is doing this properly