/etc/pro file: 

此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行。并从/etc/profile.d目录的配置文件中搜集shell的设置.
/etc/bashrc: 
为每一个运行bash shell的用户执行此文件.当bash shell被打开时,该文件被读取.
~/.bash_profile:
每个用户都可使用该文件输入专用于自己使用的shell信息,当用户登录时,该文件仅仅执行一次!默认情况下,他设置一些环境变量,执行用户的.bashrc文件.
~/.bashrc:
该文件包含专用于你的bash shell的bash信息,当登录时以及每次打开新的shell时,该该文件被读取.
~/.bash_logout:
当每次退出系统(退出bash shell)时,执行该文件.

另外,/etc/profile中设定的变量(全局)的可以作用于任何用户,而~/.bashrc等中设定的变量(局部)只能继承/etc/profile中的变量,他们是"父子"关系. 
~/.bash_profile 是交互式、login 方式进入 bash 运行的
~/.bashrc 是交互式 non-login 方式进入 bash 运行的
通常二者设置大致相同,所以通常前者会调用后者。

* 每次bash作为login shell启动时会执行.bash_profile。

主要有(我所知道的)有以下几种情形:

a) 每次登录到服务器时默认启动的shell

b) “su -l [USER]”时进入的shell

c) “bash --login”进入的shell

* 每次bash作为普通的交互shell(interactive shell)启动时会执行.bashrc

常见的有:

i) “su [USER]”进入的shell
ii) 直接运行“bash”命令进入的shell。

** 注意

1, 在shell脚本中“#!/usr/bin/bash”启动的bash并不执行.bashrc。因为这里的bash不是
    interactive shell。

2, bash作为login shell(login bash)启动时并不执行.bashrc。虽然该shell也是interactive shell,
   但它不是普通的shell。

* 一般.bash_profile里都会调用.bashrc

尽管login bash启动时不会自动执行.bashrc,惯例上会在.bash_profile中显式调用.bashrc。

,-------------------------------------
| if [ -f ~/.bashrc ]; then
|    . ~/.bashrc
| fi
`-------------------------------------

.bash_profile显示内容如下:
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

# User specific environment and startup programs

PATH=.:$PATH:$HOME/bin
BASH_ENV=$HOME/.bashrc
USERNAME="root"

export USERNAME BASH_E

.bash_profile和.bashrc说明相关推荐

  1. Linux下环境变量配置方法梳理(.bash_profile和.bashrc的区别)

    博客园 首页 新随笔 联系 管理 订阅 <div class="blogStats"><!--done--> 随笔- 556  文章- 38  评论- 77 ...

  2. .bash_profile和.bashrc的区别(如何设置生效)

    /etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行. 并从/etc/profile.d目录的配置文件中搜集shell的设置. /etc/bashrc:为每一 ...

  3. linux 下/etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc 的区别

    linux 下/etc/profile./etc/bashrc.~/.bash_profile.~/.bashrc 的区别 /etc/profile./etc/bashrc.~/.bash_profi ...

  4. Linux: .bash_profile 与 .bashrc 的区别

    [.bash_profile 与 .bashrc 的区别] .bash_profile is executed for login shells, while .bashrc is executed ...

  5. 关于“.bash_profile”和“.bashrc”区别的总结

    bash的startup文件 Linux shell是用户与Linux系统进行交互的媒介,而bash作为目前Linux系统中最常用的shell,它支持的startup文件也并不单一,甚至容易让人感到费 ...

  6. Mac和Ubuntu系统下.bash_profile和.bashrc文件

    Mac和Ubuntu系统下.bash_profile和.bashrc文件 本文部分参考Josh Staiger文章. Mac和Ubuntu系统下bash_profile和bashrc文件 前言 log ...

  7. 【Shell脚本进阶】从此彻底搞懂 Linux 环境变量及 Shell 启动文件 /etc/profile 、 ~/.bash_profile 和 ~/.bashrc(建议收藏)

    文章目录 1. 环境变量详解 1.1 全局环境变量 1.2 本地环境变量 1.3 自定义环境变量 1.3.1 自定义本地环境变量 1.3.2 自定义全局环境变量 1.4 删除环境变量 2. 启动文件详 ...

  8. linux启动 profile,Linux 启动时profile、bashrc、~/.bash_profile、~/.bashrc、~/.bash_profile执行顺序以及文件说明...

    Linux 启动时profile.bashrc.~/.bash_profile.~/.bashrc.~/.bash_profile执行顺序以及文件说明 一.执行顺序 登录linux时,/etc/pro ...

  9. linux环境变量又叫局部变量的区别,Linux下环境变量(.bash_profile和.bashrc的区别)...

    在linux系统下,如果下载并安装了应用程序,在启动时很有可能在键入它的名称时出现"command not found"的提示内容.如果每次都到安装目标文件夹内,找到可执行文件 来 ...

  10. /etc/profile ,/etc/bashrc ,~/.bash_profile,~/ .bashrc 区别与联系

    /etc/profile 针对系统中的每个用户,首次登录时被一次执行: /etc/bashrc 每次运行bash shell的用户都执行此文件,当bash被打开时,该文件被读取: ~/.bash_pr ...

最新文章

  1. bzoj 1731 [Usaco2005 dec]Layout 排队布局——差分约束
  2. shell按长度排序
  3. python弹幕代码_只需3 行代码就可以获取B站(弹幕、评论、用户)数据
  4. WebsocketWebSSH
  5. Java Web之文件的上传及下载
  6. 如何实现远程登陆,如何实现远程桌面
  7. 《四世同堂》金句摘抄(十七)
  8. python使用 GPUs
  9. c语言多线程的建立视频,如何用C语言实现多线程
  10. web端兼容性测试相关知识
  11. 【计算机视觉-从入门到精通系列】 第一章 基础知识
  12. linux下安装php扩展curl
  13. Redis 如何存储上亿级别的用户状态?
  14. Asp.net中的页面乱码的问题
  15. 计算机windows7更新失败,win7笔记本电脑配置update失败如何解决
  16. 运动控制器PSO位置同步输出(一):硬件平台与PSO指令简介
  17. android 版本权限差别,安卓手机root前后有什么区别 root后哪些高权限操作
  18. dnf时装补丁教程_dnf时装补丁怎么用?DNF时装补丁教程
  19. 夏天来了,教你怎么选西瓜
  20. 2020美团笔试题目:送餐小区数量

热门文章

  1. TIOBE 发布 8 月编程语言榜单:C# 排名如何?
  2. 又到618,.NET 千万级秒杀架构到底有多牛
  3. .NET 应用如何优雅的做功能开关(Feature Flag)
  4. Winform 进度条弹窗和任务控制
  5. 跟我一起学Redis之看完这篇比常人多会三种类型实战(又搞了几个小时)
  6. ASP.NET Core 3.x启动时运行异步任务(一)
  7. 动态 Restful API 生成
  8. 如何利用.NETCore向Azure EventHubs准实时批量发送数据?
  9. Blazor WebAssembly 3.2.0 Preview 4 如期发布
  10. 致所有.Net者和有梦想的朋友们 - 共勉