得过且过 发表于 2018-8-23 10:15:27

登入shell和非登入shell的区别

  使用启动脚本,可以让自定义的环境一劳永逸。
  这些脚本在shell被创建时运行
  根据shell是登入shell还是非登入shell,所运行的启动脚本也会不一样
  我们“su - ”是登入shell;“su ”是非登入shell
  放在启动脚本中典型的包括:
  ① 本地变量设置,特别是PS1
  比如,我的:
view plaincopy
[*]  tail -f .bash_profile | grep -n --color=auto 'PS1'
[*]  10:export PS1='[\u@10gR2 \W \$]'
  ② 环境变量例如 PATH
  ③ 别名
  ④ umask
  ㈠ 登入shell
  /etc/profile 是登入shell启动后运行的第一个启动脚本
  它只为登入shell运行;非登入shell不会引发这个脚本
  登入shell加载启动脚本的顺序为:
  /etc/profile → /etc/profile.d → .bash_profile → .bashrc → /etc/bashrc
  每个调用的脚本会依次撤销前一个调用脚本中的改变
  在退出登入shell时,我们还可以执行某些任务,如创建自动备份、清除临时文件
  把这些任务放在.bash_logout文件中
  ㈡ 非登入shell
  非登入shell加载启动脚本的顺序:
  .bashrc → /etc/bashrc → /etc/profile.d

页: [1]
查看完整版本: 登入shell和非登入shell的区别