如何从gvim中获取环境变量

时间:2022-09-13 00:20:30

When I start gvim from withing a terminal, I can access my all environment variables.

当我使用终端启动gvim时,我可以访问我的所有环境变量。

But if I launch gvim from a menu or from the "Run application" launcher, all my environment variables are not accessible.

但是如果我从菜单或“运行应用程序”启动器启动gvim,则无法访问所有环境变量。

How can I access the environment variables defined in my bashrc if gvim is not launched from a terminal ?

如果没有从终端启动gvim,如何访问我的bashrc中定义的环境变量?

These variables are defined in ~/.bashrc

这些变量在〜/ .bashrc中定义

Distro: Ubuntu Intrepid

发行版:Ubuntu Intrepid

Note1: the "Run application" launcher is accessible by hitting ALT+<F2>

注1:通过按ALT + 可以访问“运行应用程序”启动器

1 个解决方案

#1


You should be able to read all of the actual environment variables, e.g.

您应该能够读取所有实际环境变量,例如

:!echo $PATH

Your problem is with personal environment variables.

您的问题是个人环境变量。

Why are you trying to read environment variables within gvim? There may be a better way of doing things.

你为什么要在gvim中读取环境变量?可能有更好的做事方式。

Scope of Environment Variables
When you log in to your computer, bash sources the .bash_profile file.
When you run a terminal it sources the .bashrc file, so your personal environment variables are available within that terminal and any subshells.

环境变量的范围登录到计算机时,bash会提供.bash_profile文件。当您运行终端时,它会获取.bashrc文件,因此您的个人环境变量可在该终端和任何子shell中使用。

Unless you're exporting the variables from your .bashrc these variables won't be available within the general environment, and they will only be available after you have run a terminal if you export them.

除非您从.bashrc导出变量,否则这些变量在一般环境中将不可用,并且只有在您导出终端后才能使用它们。

Since you're running gvim through an application launcher, nothing is reading your .bashrc file to create those environment variables for you.

由于您通过应用程序启动器运行gvim,因此没有任何内容正在读取.bashrc文件以便为您创建这些环境变量。

For some info on bourne shell environment variables, see section 9.1.2

有关bourne shell环境变量的一些信息,请参见第9.1.2节

So a good place to put:

所以放一个好地方:

MYENVIRONMENTVARIABLE=new value of environment variable
export MYENVIRONMENTVARIABLE

is within the .bash_profile, and then if you want to make any changes to the variable, make sure you export them again (and if you want the changes to be permanent, edit the .bash_profile).

在.bash_profile中,然后如果要对变量进行任何更改,请确保再次导出它们(如果您希望更改是永久性的,请编辑.bash_profile)。

Note that the value of this environment variable will be available for any new shells, but the existing shells probably won't re-read the environment variables.

请注意,此环境变量的值可用于任何新shell,但现有shell可能不会重新读取环境变量。

#1


You should be able to read all of the actual environment variables, e.g.

您应该能够读取所有实际环境变量,例如

:!echo $PATH

Your problem is with personal environment variables.

您的问题是个人环境变量。

Why are you trying to read environment variables within gvim? There may be a better way of doing things.

你为什么要在gvim中读取环境变量?可能有更好的做事方式。

Scope of Environment Variables
When you log in to your computer, bash sources the .bash_profile file.
When you run a terminal it sources the .bashrc file, so your personal environment variables are available within that terminal and any subshells.

环境变量的范围登录到计算机时,bash会提供.bash_profile文件。当您运行终端时,它会获取.bashrc文件,因此您的个人环境变量可在该终端和任何子shell中使用。

Unless you're exporting the variables from your .bashrc these variables won't be available within the general environment, and they will only be available after you have run a terminal if you export them.

除非您从.bashrc导出变量,否则这些变量在一般环境中将不可用,并且只有在您导出终端后才能使用它们。

Since you're running gvim through an application launcher, nothing is reading your .bashrc file to create those environment variables for you.

由于您通过应用程序启动器运行gvim,因此没有任何内容正在读取.bashrc文件以便为您创建这些环境变量。

For some info on bourne shell environment variables, see section 9.1.2

有关bourne shell环境变量的一些信息,请参见第9.1.2节

So a good place to put:

所以放一个好地方:

MYENVIRONMENTVARIABLE=new value of environment variable
export MYENVIRONMENTVARIABLE

is within the .bash_profile, and then if you want to make any changes to the variable, make sure you export them again (and if you want the changes to be permanent, edit the .bash_profile).

在.bash_profile中,然后如果要对变量进行任何更改,请确保再次导出它们(如果您希望更改是永久性的,请编辑.bash_profile)。

Note that the value of this environment variable will be available for any new shells, but the existing shells probably won't re-read the environment variables.

请注意,此环境变量的值可用于任何新shell,但现有shell可能不会重新读取环境变量。