Bash shell 在两行之间丢失环境变量

发布于 2024-09-06 06:15:19 字数 183 浏览 1 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼眸印温柔 2024-09-13 06:15:19

正在创建一个子 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.

筱武穆 2024-09-13 06:15:19

当您定义要供所有子 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文