美文网首页
Linux bashrc和profile

Linux bashrc和profile

作者: 零一间 | 来源:发表于2018-04-24 16:02 被阅读39次

bashrc和profile都是Shell的启动设置文件,可以为当前的Shell初始化环境变量等。

针对个别用户

.bashrc

# ~/.bashrc: executed by bash(1) for non-login shells.

.profile

# ~/.profile: executed by Bourne-compatible login shells.

针对全体用户

/etc/bash.bashrc

# System-wide .bashrc file for interactive bash(1) shells.

/etc/profile

# /etc/profile: system-wide .profile file for the Bourne shell (sh(1)

bashrc和profile的差异

  1. bashrc是在系统启动后就会自动运行。

  2. profile是在用户登录后才会运行。

  3. 进行设置后,可运用source bashrc命令更新bashrc,也可运用source profile命令更新profile。

通常我们修改bashrc,有些linux的发行版本不一定有profile这个文件

  1. /etc/profile中设定的变量(全局)的可以作用于任何用户,而~/.bashrc等中设定的变量(局部)只能继承/etc/profile中的变量,他们是”父子”关系。

执行顺序

交互式(例如会话信息):/etc/bashrc---/etc/profile.d/*.sh----~/.bash_profile---~/.bashrc_profile----~/.bashrc-----/etc/bashrc

非交互式(自动化操作):~/.bashrc-----/etc/bashrc-/etc/profile.d/*.sh

补充介绍

介绍bashrc相关的几个文件:

~/.bash_profile: 每个用户都可使用该文件输入专用于自己使用的shell信息,当用户登录时,该文件仅仅执行一次!默认情况下,他设置一些环境变量,执行用户的.bashrc文件。

~/.bash_logout: 当每次退出系统(退出bash shell)时,执行该文件。

~/.bash_profile 是交互式、login方式进入bash运行的,~/.bashrc是交互式non-login方式进入bash运行的,通常二者设置大致相同,所以通常前者会调用后者。

相关文章

网友评论

      本文标题:Linux bashrc和profile

      本文链接:https://www.haomeiwen.com/subject/kdujlftx.html