zoukankan      html  css  js  c++  java
  • Debian类系统环境变量的配置

    一、环境变量相关的配置文件

    1)/etc/profile
    全局(公有)配置,不管是哪个用户,登录时都会读取该文件。

    2)/ect/bashrc
    Ubuntu没有此文件,与之对应的是/ect/bash.bashrc
    它也是全局(公有)的
    bash执行时,不管是何种方式,都会读取此文件。

    3)~/.profile
    若bash是以login方式执行时,读取~/.bash_profile,若它不存在,则读取~/.bash_login,若前两者不存在,读取~/.profile。
    另外,图形模式登录时,此文件将被读取,即使存在~/.bash_profile和~/.bash_login。

    4)~/.bash_login
    若bash是以login方式执行时,读取~/.bash_profile,若它不存在,则读取~/.bash_login,若前两者不存在,读取~/.profile。

    5)~/.bash_profile
    Unbutu默认没有此文件,可新建。
    只有bash是以login形式执行时,才会读取此文件。通常该配置文件还会配置成去读取~/.bashrc。

    6)~/.bashrc
    当bash是以non-login形式执行时,读取此文件。若是以login形式执行,则不会读取此文件。

    7)~/.bash_logout
    注销时,且是longin形式,此文件才会读取。也就是说,在文本模式注销时,此文件会被读取,图形模式注销时,此文件不会被读取。

    二、文件执行顺序说明

    下面是在本机的几个例子:
    1)图形模式登录时,顺序读取:/etc/profile和~/.profile
    2)图形模式登录后,打开终端时,顺序读取:/etc/bash.bashrc和~/.bashrc
    3)文本模式登录时,顺序读取:/etc/bash.bashrc,/etc/profile和~/.bash_profile
    4)从其它用户su到该用户,则分两种情况:
    • 如果带-l参数(或-参数,--login参数),如:su -l username,则bash是lonin的,它将顺序读取以下配置文件:/etc/bash.bashrc,/etc/profile和~/.bash_profile。
    • 如果没有带-l参数,则bash是non-login的,它将顺序读取:/etc/bash.bashrc和~/.bashrc
    5)注销时,或退出su登录的用户,如果是longin方式,那么bash会读取:~/.bash_logout
    6)执行自定义的shell文件时,若使用“bash -l a.sh”的方式,则bash会读取行:/etc/profile和~/.bash_profile,若使用其它方式,如:bash a.sh, ./a.sh,sh a.sh(这个不属于bash shell),则不会读取上面的任何文件。
    7)上面的例子凡是读取到~/.bash_profile的,若该文件不存在,则读取~/.bash_login,若前两者不存在,读取~/.profile。

    三、sudo执行已有命令提示command not found

    有些命令在定义了PATH的情况下,普通用户可以调用而加上sudo却调用不了,报command not found的错误。
    原因是系统在编译sudo的时候加入了–with-secure-path,这个选项。

    –with-secure-path[=PATH]
    Path used for every command run from sudo(8). If you don’t trust the people running sudo to have a sane PATH environment variable you may want to use this. Another use is if you want to have the “root path” be separate from the “user path.” You will need to customize the path for your site. NOTE: this is not applied to users in the group specified by –with-exemptgroup. If you do not specify a path, “/bin:/usr/ucb:/usr/bin:/usr/sbin:/sbin:/usr/etc:/etc” is used.

    要解决这个问题有几种方法:

    1)重新编译sudo,不加–with-secure-path选项

    2)执行命令时使用绝对路径

    如:sudo /home/test/code/go/bin/dlv

    3)在环境配置文件里加一个alias【推荐】

    例如在/etc/bash.bashrc里添加:alias sudo='sudo env PATH=$PATH:/usr/local/sbin:/sbin'

    我们可以在root权限下先查看一下PATH和当前用户PATH的区别,然后再追加路径。

    重新登录后生效,这样我们在执行sudo dlv命令时就等于sudo env PATH=$PATH dlv

  • 相关阅读:
    【洛谷6620】[省选联考 2020 A 卷] 组合数问题(下降幂)
    【AtCoder】AtCoder Grand Contest 033 解题报告
    【AtCoder】AtCoder Grand Contest 034 解题报告
    【洛谷5445】[APIO2019] 路灯(树套树)
    【LOJ6059】「2017 山东一轮集训 Day1」Sum(倍增优化数位DP+NTT)
    【LOJ6159】「美团 CodeM 初赛 Round A」最长树链(树的直径)
    重新入门的Polya定理
    【洛谷6105】[Ynoi2010] y-fast trie(set)
    【BZOJ4480】 [JSOI2013] 快乐的jyy(回文自动机裸题)
    【LOJ6172】Samjia 和大树(树形DP+猜结论)
  • 原文地址:https://www.cnblogs.com/realjimmy/p/13379700.html
Copyright © 2011-2022 走看看