您的位置:首页 > 运维架构 > Shell

Bash Shell配置文件解析(based on ubuntu 10.04 LTS)

2012-02-14 15:01 477 查看
文件 /etc/profile:

root@keen-home:/etc/profile.d# cat /etc/profile

# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))

# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

if [ -d /etc/profile.d ]; then  <==判断读取目录 /etc/profile.d 目录下的sh脚本

  for i in /etc/profile.d/*.sh; do

    if [ -r $i ]; then

      . $i

    fi

  done

  unset i

fi

#以上就是读取目录 /etc/profile.d 下的sh脚本,而我们通过查看,发现该目录下只有一个文件:speechd-user-port.sh

#而且该文件里面只有一条语句:export SPEECHD_PORT=$(expr 6560 + $(getent passwd $USER | cut -f 3 -d :))

#显然是设置了一个环境变量SPEECHD_PORT,其值是6560与一个数x的和,而这个x为getent passwd $USER | cut -f 3 -d : 的结果

#我们运行这个命令getent passwd $USER  得到:root:x:0:0:root:/root:/bin/bash,而该结果与/etc/passwd中root对应的行一致。然后对该行以“:”为分隔符取第三个域,即为0。

#我们知道/etc/passwd文件中每一行的内容为:登陆名:可选的加密后的密码:userid:groupid:用户名:用户的家目录:用户默认shell,则,

#这个环境变量就是6560+userid 

if [ "$PS1" ]; then

  if [ "$BASH" ]; then

    PS1='\u@\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

#以上这段是设置用户的命令提示符并读取配置文件/etc/bash.bashrc

umask 022

#设置文件掩码022
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息