linux环境变量

linux环境变量

定义

(1)login shell:取得bash 时须要完整的登入流程,就称为login shell。举例来讲,同tty1~tty6登入时,须要输入用户名和密码,此时取得的bash就称为login shellhtml

(2)non-login shell:取得bash介面的方法不须要重复登入的动做。linux

举两个例子
(i)以X window登入linux后,再以X的图形化介面启动终端机,此时那个终端机并不须要再次的输入用户名和密码,那个bash的环境就称为non-login shell
(ii)在本来的bashr环境中再次下达bash这个指令,一样没有要求输入用户名和密码,那个第二个bash也是non-login shellweb

Login Shell Sessions&&Nonlogin Shell Session

Login Shell Sessions:shell

  • /etc/profile : a global configuration script that applies to all users.
  • ~/.bash_profile : a user’s personal startup file.can be used to extend or overide settings in the global configuration script.
  • ~/.bash_login : if ~/.bash_profile is not found,bash attempts to read this script.
  • ~/.profile : if neither ~/.bash_profile nor ~/.bash_login is found,bash attempts to read this file. This is the default in Debian-based distributions,such as Ubuntu.

Nonlogin Shell Sessions:bash

  • /etc/bash.bashrc a global configuration script that applies to all users.
  • ~/.bashrc a user’s personal startup file. Can be used to extend or override settings in the global configuration script.

.bashrc与.bash_profile区别

  • .bashrc登陆以及打开新的shell时,该文件被读取。
  • .bash_profile默认状况之下,它用来设置一些环境变量,执行用户的.bashrc文件。
  • 执行顺序分为:.bash_profile 、bash_login、profile,而且在~/.bash_profile中通常含有如下代码:
  1. if [ -f ~/.bashrc ] ; then 
  2. . ~/.bashrc 
  3. fi 

~/.bashrc中还会有如下代码:session

  1. if [ -f /etc/bashrc ] ; then 
  2. . /bashrc 
  3. fi 

因此,~/.bashrc会调用 /etc/bashrc文件。最后,在退出shell时,还会执行 ~/.bash_logout文件。
执行顺序为:/etc/profile -> (~/.bash_profile | ~/.bash_login | ~/.profile) -> ~/.bashrc -> /etc/bashrc -> ~/.bash_logout
注:/etc/profile: 此文件为系统的每一个用户设置环境信息,当用户第一次登陆时,该文件被执行. 并从/etc/profile.d目录的配置文件中搜集shell的设置。app

相关文章
相关标签/搜索