环境变量配置文件简介

来源:互联网 发布:傲剑双龙斩升级数据 编辑:程序博客网 时间:2024/06/01 15:39

Part 1:环境变量配置文件简介

前面的在介绍shell编程:变量中就介绍了环境变量的设置方法,但是那都是临时生效的,在系统重启之后就会失去作用,所以为了保证环境变量永久生效,就需要修改相对应的配置文件。

环境变量配置文件中主要是定义对系统操作环境生效的系统默认环境变量。

Extra: source 配置文件 或者 . 配置文件

介绍一下后面这个,.(空格)配置文件,的命令,这样的方式与直接使用source命令的作用是一致的,都能使配置文件在不重新登录的情况下起作用。

Part 2:环境变量配置文件作用

这里写图片描述

以上图片就是CentOX 6上开机时运行的配置文件顺序。我在Ubuntu 16.04 LTS上尝试一下。

2.1 /etc/profile

# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).# 由于$PS1实在这个配置文件 ./etc/bash.bashrc 中定义的,所以开始不会运行 ./etc/bash.bashrc,但是$BASH这个变量是定义好的if [ "$PS1" ]; then  if [ "$BASH" ] && [ "$BASH" != "/bin/sh" ]; then    # The file bash.bashrc already sets the default PS1.    # PS1='\h:\w\$ '    if [ -f /etc/bash.bashrc ]; then      . /etc/bash.bashrc    fi  else    if [ "`id -u`" -eq 0 ]; then      PS1='# '    else      PS1='$ '    fi  fifi# 所以接着该文件运行的就是 /etc/profile.d/ 中的所有以 .sh 结尾的shell脚本文件if [ -d /etc/profile.d ]; then  for i in /etc/profile.d/*.sh; do    if [ -r $i ]; then      . $i    fi  done  unset ifi

2.2 /etc/profile.d/*.sh

该目录下的所有文件有:

  • appmenu-qt5.sh
  • apps-bin-path.sh
  • bash_completion.sh
  • cedilla-portuguese.sh
  • vte-2.91.sh

按照原本图上的lang.sh就没有了,该文件是定义语系的,就是这里。下面就没法查看了。

2.3 /etc/sysc config/i18n

这个文件是什么鬼,我在Ubuntu上没有找到。

———————–到此为止,下面的顺序就运行完了,接下来就是上面部分了。——————–

2.4 ~/.bash_profile

“~”表示家目录,每个用户都有自己对应的家目录。该文件在Ubuntu中就是 ~/.profile,里面的内容是:

# ~/.profile: executed by Bourne-compatible login shells.# 这个参数前面哪个文件设置过得,所以下面就是执行 ~/.bashrcif [ "$BASH" ]; then  if [ -f ~/.bashrc ]; then    . ~/.bashrc  fifimesg n || true

2.5 ~/.bashrc

这个文件里面有两个内容,是以前讲过的,还有这个之后运行的 /etc/bashrc 这个文件我在 /etc/ 目录下没有查到。

2.5.1 历史命令最大保留条数:HISTSIZE

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)HISTSIZE=1000HISTFILESIZE=2000

2.5.2 别名设置配置文件:alias 别名=”原始命令”

2.6 退出(logout)时执行的配置文件:~/.bash_logout

这个配置文件我在自己的版本下没有看到。

2.7 历史命令保存文件:~/bash_history

Part 3:shell登录信息

3.1 本地终端欢迎信息:/etc/issue

注意,是本地终端。

这里写图片描述

我的配置文件的内容是:

Ubuntu 16.04 LTS \n \l

在开机时,还没有切换到图形界面前,命令行中显示的就是这个信息。

3.2 远程终端欢迎信息:/etc/issue.net

这里写图片描述

3.3 登录后欢迎信息:/etc/motd

这个文件在我系统上没看到。

0 0
原创粉丝点击