首页服务器Web服务器 Linux中环境变量配置的步骤详解

Linux中环境变量配置的步骤详解

简介 我们大家在平时使用Linux的时候,经常需要配置一些环境变量,这时候一般都是网上随便搜搜就有人介绍经验的。不过问题在于他们的方法各不相同,有人说配置在/etc/profile里,…

简介

我们大家在平时使用Linux的时候,经常需要配置一些环境变量,这时候一般都是网上随便搜搜就有人介绍经验的。不过问题在于他们的方法各不相同,有人说配置在/etc/profile里,有人说配置在/etc/environment,有人说配置在~/.bash_profile里,有人说配置在~/.bashrc里,有人说配置在~/.bash_login里,还有人说配置在~/.profile里。。。这真是公说公有理。。。那么问题来了,Linux到底是怎么读取配置文件的呢,依据又是什么呢?下面这篇文章就来给大家详细的介绍下,一起来看看吧。

文档

我一向讨厌那种说结论不说出处的行为,这会给人一种“我凭什么相信你”的感觉。而且事实上没有出处就随便议论得出的结论也基本上是人云亦云的。事实上,与其去问别人,不如去问文档。 找了一会,发现关于环境变量配置的相关文档其实是在bash命令的man文档里,毕竟我们常用的就是这个shell。

在$man bash里,我发现了下面的一段文字:

INVOCATION  A login shell is one whose first character of argument zero is a -, or  one started with the --login option.  An interactive shell is one started without non-option arguments and  without the -c option whose standard input and error are both connected  to terminals (as determined by isatty(3)), or one started with the -i  option. PS1 is set and $- includes i if bash is interactive, allowing  a shell script or a startup file to test this state.  The following paragraphs describe how bash executes its startup files.  If any of the files exist but cannot be read, bash reports an error.  Tildes are expanded in filenames as described below under Tilde Expan‐  sion in the EXPANSION section.  When bash is invoked as an interactive login shell, or as a non-inter‐  active shell with the --login option, it first reads and executes com‐  mands from the file /etc/profile, if that file exists. After reading  that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile,  in that order, and reads and executes commands from the first one that  exists and is readable. The --noprofile option may be used when the  shell is started to inhibit this behavior.  When a login shell exits, bash reads and executes commands from the  file ~/.bash_logout, if it exists.  When an interactive shell that is not a login shell is started, bash  reads and executes commands from /etc/bash.bashrc and ~/.bashrc, if  these files exist. This may be inhibited by using the --norc option.  The --rcfile file option will force bash to read and execute commands  from file instead of /etc/bash.bashrc and ~/.bashrc.  When bash is started non-interactively, to run a shell script, for  example, it looks for the variable BASH_ENV in the environment, expands  its value if it appears there, and uses the expanded value as the name  of a file to read and execute. Bash behaves as if the following com‐  mand were executed:    if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi  but the value of the PATH variable is not used to search for the file‐  name.
本文来自网络,不代表1号站长-站长学院|资讯交流平台立场。转载请注明出处: https://www.1cn.cc/fwq/web/3213.html
上一篇centos 7系统下安装Jenkins的步骤详解
下一篇 docker中修改镜像容器的存放目录的方法
admin

作者: admin

这里可以再内容模板定义一些文字和说明,也可以调用对应作者的简介!或者做一些网站的描述之类的文字或者HTML!

为您推荐

评论列表()

    联系我们

    联系我们

    0898-88888888

    在线咨询: QQ交谈

    邮箱: email@wangzhan.com

    工作时间:周一至周五,9:00-17:30,节假日休息

    关注微信
    微信扫一扫关注我们

    微信扫一扫关注我们

    关注微博
    返回顶部