Bash运行相关的配置文件,摘自man pageshell
##/etc/profileubuntu
/etc/profile:此文件为系统的每一个用户设置环境信息,当用户第一次登陆时,该文件被执行.并从/etc/profile.d目录的配置文件中搜集shell的设置.bash
例如ubuntu下/etc/profile的默认内容以下:ide
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1)) # and Bourne compatible shells (bash(1), ksh(1), ash(1), ...). 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 fi fi # The default umask is now handled by pam_umask. # See pam_umask(8) and /etc/login.defs. if [ -d /etc/profile.d ]; then for i in /etc/profile.d/*.sh; do if [ -r $i ]; then . $i fi done unset i fi
`code
前半段主要是加载/etc/bash.bashrc的内容,后半段则是加载bash的一些初始化脚本,例如bash补全设置。input
##~/.bashrc和/etc/bashrc /etc/bashrc: 为每个运行bash shell的用户执行此文件.当bash shell被打开时,该文件被读取。it
/etc/environment是设置整个系统的环境 * 最典型的是ubuntu里的全局path设置io
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
##执行顺序 /etc/environment -> /etc/profile -> /etc/bashrc -> ~/profile -> ~/.bashrc 后面设置的会覆盖前面的设置。zsh
##bashrc的一点配置原则 对于/etc/bashrc来讲,我的感受应该尽最小配置原则,只有肯定全部用户都用的到的配置才写到里面。事实上Debian干脆默认就没有/etc/bashrc这个文件,每当新建一个用户的时候,都根据从/etc/skel/的模版文件生成一份用户的~/.bashrc和~/.profile。若是你把太多的配置都集中到/etc/bashrc中,某些特殊须要的用户就须要在本身的文件中覆盖这些选项,与上一种方法相比,增长了人工,得不偿失。table