Linux: where are environment variables stored?

后端 未结 5 1236
旧巷少年郎
旧巷少年郎 2020-12-02 05:13

If I type into a terminal,

export DISPLAY=:0.0

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

I\'m using Ubuntu 8.10. I\

相关标签:
5条回答
  • 2020-12-02 05:50

    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.

    0 讨论(0)
  • 2020-12-02 05:52

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

    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.

    0 讨论(0)
  • 2020-12-02 05:59

    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)

    0 讨论(0)
  • 2020-12-02 06:07

    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

    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 讨论(0)
  • 2020-12-02 06:08

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

    0 讨论(0)
提交回复
热议问题