Linux:环境变量存储在哪里?

时间:2022-06-28 23:05:41

If I type into a terminal,

如果我输入一个终端,

export DISPLAY=:0.0

... where is the shell storing that environment variable?

…存储环境变量的shell在哪里?

I'm using Ubuntu 8.10. I've looked in the files ~/.profile and /etc/profile and can find no trace of DISPLAY.

我使用Ubuntu 8.10。我看了文件~/。配置文件和/etc/profile不能找到显示的痕迹。

5 个解决方案

#1


91  

The environment variables of a process exist at runtime, and are not stored in some file or so. They are stored in the process's own memory (that's where they are found to pass on to children). But there is a virtual file in

进程的环境变量在运行时存在,并不存储在某个文件中。它们存储在进程自己的内存中(这是它们被发现传递给儿童的地方)。但是里面有一个虚拟文件

/proc/pid/environ

This file shows all the environment variables that were passed when calling the process (unless the process overwrote that part of its memory — most programs don't). The kernel makes them visible through that virtual file. One can list them. For example to view the variables of process 3940, one can do

这个文件显示了调用进程时传递的所有环境变量(除非进程覆盖了它内存的那一部分——大多数程序没有)。内核通过这个虚拟文件使它们可见。人可以列出他们。例如,要查看进程3940的变量,可以这样做

cat /proc/3940/environ | tr '\0' '\n'

Each variable is delimited by a binary zero from the next one. tr replaces the zero into a newline.

每个变量都由下一个的二进制0分隔。tr将0替换为换行符。

#2


28  

Type "set" and you will get a list of all the current variables. If you want something to persist put it in ~/.bashrc or ~/.bash_profile (if you're using bash)

键入“set”,您将得到所有当前变量的列表。如果你想要某物持久存在,请把它放在~/中。bashrc或(~ /。bash_profile(如果使用bash)

#3


8  

If you want to put the environment for system-wide use you can do so with /etc/environment file.

如果您想要在系统范围内使用环境,可以使用/etc/environment文件。

#4


7  

It's stored in the process (shell) and since you've exported it, any processes that process spawns.

它存储在进程(shell)中,由于您已经导出了它,因此任何进程都会生成它。

Doing the above doesn't store it anywhere in the filesystem like /etc/profile. You have to put it there explicitly for that to happen.

执行上述操作并不会将其存储在/etc/ profilefile这样的文件系统中。你必须把它显式地放在那里,这样才能发生。

#5


-7  

That variable isn't stored in some script. It's simply set by the X server scripts. You can check the environment variables currently set using set.

这个变量没有存储在某个脚本中。它只是由X服务器脚本设置的。您可以使用set检查当前设置的环境变量。

#1


91  

The environment variables of a process exist at runtime, and are not stored in some file or so. They are stored in the process's own memory (that's where they are found to pass on to children). But there is a virtual file in

进程的环境变量在运行时存在,并不存储在某个文件中。它们存储在进程自己的内存中(这是它们被发现传递给儿童的地方)。但是里面有一个虚拟文件

/proc/pid/environ

This file shows all the environment variables that were passed when calling the process (unless the process overwrote that part of its memory — most programs don't). The kernel makes them visible through that virtual file. One can list them. For example to view the variables of process 3940, one can do

这个文件显示了调用进程时传递的所有环境变量(除非进程覆盖了它内存的那一部分——大多数程序没有)。内核通过这个虚拟文件使它们可见。人可以列出他们。例如,要查看进程3940的变量,可以这样做

cat /proc/3940/environ | tr '\0' '\n'

Each variable is delimited by a binary zero from the next one. tr replaces the zero into a newline.

每个变量都由下一个的二进制0分隔。tr将0替换为换行符。

#2


28  

Type "set" and you will get a list of all the current variables. If you want something to persist put it in ~/.bashrc or ~/.bash_profile (if you're using bash)

键入“set”,您将得到所有当前变量的列表。如果你想要某物持久存在,请把它放在~/中。bashrc或(~ /。bash_profile(如果使用bash)

#3


8  

If you want to put the environment for system-wide use you can do so with /etc/environment file.

如果您想要在系统范围内使用环境,可以使用/etc/environment文件。

#4


7  

It's stored in the process (shell) and since you've exported it, any processes that process spawns.

它存储在进程(shell)中,由于您已经导出了它,因此任何进程都会生成它。

Doing the above doesn't store it anywhere in the filesystem like /etc/profile. You have to put it there explicitly for that to happen.

执行上述操作并不会将其存储在/etc/ profilefile这样的文件系统中。你必须把它显式地放在那里,这样才能发生。

#5


-7  

That variable isn't stored in some script. It's simply set by the X server scripts. You can check the environment variables currently set using set.

这个变量没有存储在某个脚本中。它只是由X服务器脚本设置的。您可以使用set检查当前设置的环境变量。