zoukankan      html  css  js  c++  java
  • linux环境变量

    linux环境变量

    定义

    (1)login shell:取得bash 时需要完整的登入流程,就称为login shell。举例来说,同tty1~tty6登入时,需要输入用户名和密码,此时取得的bash就称为login shell

    (2)non-login shell:取得bash介面的方法不需要重复登入的动作。

    举两个例子
    (i)以X window登入linux后,再以X的图形化介面启动终端机,此时那个终端机并不需要再次的输入用户名和密码,那个bash的环境就称为non-login shell
    (ii)在原本的bashr环境中再次下达bash这个指令,同样没有要求输入用户名和密码,那个第二个bash也是non-login shell

    Login Shell Sessions&&Nonlogin Shell Session

    Login Shell Sessions:

    • /etc/profile : a global configuration script that applies to all users.
    • ~/.bash_profile : a user’s personal startup file.can be used to extend or overide settings in the global configuration script.
    • ~/.bash_login : if ~/.bash_profile is not found,bash attempts to read this script.
    • ~/.profile : if neither ~/.bash_profile nor ~/.bash_login is found,bash attempts to read this file. This is the default in Debian-based distributions,such as Ubuntu.

    Nonlogin Shell Sessions:

    • /etc/bash.bashrc a global configuration script that applies to all users.
    • ~/.bashrc a user’s personal startup file. Can be used to extend or override settings in the global configuration script.

    .bashrc与.bash_profile区别

    • .bashrc登录以及打开新的shell时,该文件被读取。
    • .bash_profile默认情况之下,它用来设置一些环境变量,执行用户的.bashrc文件。
    • 执行顺序分为:.bash_profile 、bash_login、profile,并且在~/.bash_profile中一般含有以下代码:
    1. if [ -f ~/.bashrc ] ; then 
    2. . ~/.bashrc 
    3. fi 

    ~/.bashrc中还会有以下代码:

    1. if [ -f /etc/bashrc ] ; then 
    2. . /bashrc 
    3. fi 

    所以,~/.bashrc会调用 /etc/bashrc文件。最后,在退出shell时,还会执行 ~/.bash_logout文件。
    执行顺序为:/etc/profile -> (~/.bash_profile | ~/.bash_login | ~/.profile) -> ~/.bashrc -> /etc/bashrc -> ~/.bash_logout
    注:/etc/profile: 此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行. 并从/etc/profile.d目录的配置文件中搜集shell的设置。

  • 相关阅读:
    干掉 LaTeX !用BookDown写本书
    Java面试指北!13个认证授权常见面试题/知识点总结!| JavaGuide
    写了个简洁的Typora+Markdown简历模板
    有哪些可以提高代码质量的书籍推荐?
    京东数科面试真题:常见的 IO 模型有哪些?Java 中的 BIO、NIO、AIO 有啥区别?
    国内有哪些顶级技术团队的博客值得推荐?
    两万字长文总结,梳理 Java 入门进阶那些事
    藏在栈里的金丝雀
    surging 如何使用流媒体服务
    低代码平台--基于surging开发微服务编排流程引擎构思
  • 原文地址:https://www.cnblogs.com/forest-wow/p/7259213.html
Copyright © 2011-2022 走看看