• 请不要在回答技术问题时复制粘贴 AI 生成的内容
asanelder
V2EX  ›  程序员

PATH 是何时 export 的?

  •  
  •   asanelder · Dec 8, 2020 · 1352 views
    This topic created in 1992 days ago, the information mentioned may be changed or developed.
    俺用的是 bash 。俺的环境没有.bash_profile, .bash_login,只有.profile, 和.bashrc

    在 profile 中设置了 PATH 变量,但俺没有找到 export PATH 的地方。

    但 env 显示 PATH 已经设置成环境变量了。。

    求知道的铁子告知一二
    5 replies    2020-12-09 15:00:45 +08:00
    boris93
        1
    boris93  
       Dec 8, 2020 via Android
    看看 /etc/profile ?
    asanelder
        2
    asanelder  
    OP
       Dec 8, 2020
    @boris93 #1 /etc/profile 中也没有。

    俺找到答案了
    https://unix.stackexchange.com/questions/26047/how-to-correctly-add-a-path-to-path

    看这里面的意思,PATH 是在很早很早之前就被设置成了环境变量了,而 shell 中的 PATH 就是继承过来的,所以不需要再 export 了。

    也就是说 PATH 是先于 shell 存在的。
    12101111
        3
    12101111  
       Dec 8, 2020
    /usr/include/paths.h 这个 PATH 是 libc 写死的, POSIX 标准要求的, 这样 pid1(init)就会使用_PATH_STDPATH 里的 PATH,然后读取系统配置文件,这样其他的进程也就继承了 init 的 PATH
    asanelder
        4
    asanelder  
    OP
       Dec 8, 2020
    @12101111 #3 感谢提供更多细节,俺刚找到的答案也是说 shell 的祖先进程已经设置了的,
    julyclyde
        5
    julyclyde  
       Dec 9, 2020
    你可以顺着 pstree 往上找一下
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2875 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 466ea39e · 58ms · UTC 04:41 · PVG 12:41 · LAX 21:41 · JFK 00:41
    ♥ Do have faith in what you're doing.