• linux系统用户登陆时脚本执行顺序


    在用户登录的时候执行sh脚本的顺序:每次登录的时候都会完全执行的
    /etc/profile.d/file
    /etc/profile
    /etc/bashrc
    /root/.bashrc
    /root/.bash_profile
    所以如果你想覆盖的话你也就知道了怎么去覆盖

    如果想弄明白以上的问题,尝试着去读man bash这是最直观的说明了。

    名词理解:

    1. login shell:例如tty1-tty6登陆时候要输入用户名密码,就是login shell,
      解析如下文件
      /etc/profile
      ~/.bash_profile
      ~/.bash_login
      ~/.profile
    2. non login shell:
    3. interactive shell: 交互式
    4. non-interactively:非交互式

    A login shell is one whose first character of argument zero is a -, or one started with the –login option.

    交互式login shell的情况如下:
    When bash is invoked as an interactive login shell, or as a non-interactive shell with the –login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The –noprofile option may be used when the shell is started to inhibit this behavior.(使用–noprofile选项激活Bash可以禁止其读任何初始化文件)
    When a login shell exits, bash reads and executes commands from the files ~/.bash_logout and /etc/bash.bash_logout, if the files exists.
    交互式 non login shell情况如下:
    When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists. This may be inhibited by using the –norc option. The –rcfile file option will force bash to read and execute commands from file instead of ~/.bashrc.

    非交互式
    当运行shell脚本时,bash是非交互式的
    在interactive shell下执行脚本,将会启动non-interactive shell, non-interactive shell从其父进程处继承环境变量

    环境变量用户变量永久变量临时变量(这些概念这的很乱)
    env
    export
    set
    unset

    如果能够搞清楚这些东西,也就清楚了linux的变量是从哪里来的了,也就明白了,shell变量不过如此,而且也明白了shell变量和linux内核真的是相距甚远。我们最容易犯的错误就是所见即所得,我们总是以为bash是linux,其实不然,bash只是一层壳,而真正的linux内核的各种资源分配,线程调度才是linux内核。

    问题:当我们输入一个命令时,linux是怎么去解析的?
    我想会去搜索这个命令并执行这个命令。

  • 相关阅读:
    vue使用百度统计埋点
    修改JAVA字节码
    由前序遍历和中序遍历构建二叉树-Python
    二叉树的最大深度-Python
    二叉树的层序遍历-Python
    判断是否是对称二叉搜索树
    什么是主动学习方法
    验证二叉搜索树-Python
    DevExpress如何汉化XAF
    python install 失败?
  • 原文地址:https://www.cnblogs.com/yzwone/p/12527603.html
Copyright © 2020-2023  润新知