登录式shell和非登录式shell

走远了吗. 提交于 2020-02-06 15:24:32

登录shell的途径

了解两种方式之间的区别,就要先了解shell的配置文件:
  • bash的配置文件

    • 全局配置文件
      • /etc/profile
      • /etc/profile.d/*
      • /etc/bashrc
    • 个人配置文件
      • ~/.bash_profile
      • ~/,bashrc
  • 由上可知,bash的配置文件分别为profile类文件和bashrc类文件:

    • profile类文件作用:
      • 1.设定环境变量
      • 2.运行命令或脚本(登录时运行的脚本)。
    • bashrc类文件配置作用:
      • 1.设定本地变量。
      • 2.定义命令别名
了解以上配置文件后,则:
  • 登录式shell 读取配置 文件过程:
    • /etc/profile –> /etc/profile.d/*.sh –> ~ /.bash_profile –> ~ /bashrc –> /etc/bashrc
  • 非登录式shell 读取配置 文件过程:
    • ~ /.bashrc –> /etc/bashrc –> /etc/prodile.d/*.sh
而登录式shell和非登录式shell的运行形式如下:
  • 登录式shell:
    • 正常通过某终端登录的shell。
    • su - username
    • su -l username
  • 非登录式shell:
    • su username
    • 图形终端下打开的命令窗口。
    • 自动执行的shell脚本。
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!