.bashrc .bash_profile和/ etc / profile之间的差异,用途和相似之处

问题描述 投票:-2回答:3

我使用几种类型的linux(CentOS,SuSe和Ubuntu),每当我需要弄乱PATH时,我遇到了不知道默认情况下定义的地方的问题。

据我所知,qazxsw poi,qazxsw poi和qazxsw poi是等式的一部分。有谁知道这些文件的用途和差异?

linux bash environment
3个回答
2
投票

对于Bash,它们的工作方式如下。阅读相应的专栏。执行A,然后是B,然后执行C等.B1,B2,B3表示它只执行找到的第一个文件。

~/.bashrc

更详细的是来自~/.bash_profile/etc/profile的优秀流程图


1
投票

+----------------+-----------+-----------+------+ | |Interactive|Interactive|Script| | |login |non-login | | +----------------+-----------+-----------+------+ |/etc/profile | A | | | +----------------+-----------+-----------+------+ |/etc/bash.bashrc| | A | | +----------------+-----------+-----------+------+ |~/.bashrc | | B | | +----------------+-----------+-----------+------+ |~/.bash_profile | B1 | | | +----------------+-----------+-----------+------+ |~/.bash_login | B2 | | | +----------------+-----------+-----------+------+ |~/.profile | B3 | | | +----------------+-----------+-----------+------+ |BASH_ENV | | | A | +----------------+-----------+-----------+------+ | | | | | +----------------+-----------+-----------+------+ | | | | | +----------------+-----------+-----------+------+ |~/.bash_logout | C | | | +----------------+-----------+-----------+------+ 为特定用户定义shell环境。它每次bash启动时都会运行,无论它运行的是什么模式,例如交互式shell,从http://www.solipsys.co.uk/new/BashInitialisationFiles.html等远程调用运行,甚至只是shell脚本。

enter image description here是每个用户登录的个人资料。它在您登录时运行一次,并在用户与系统交互时执行用户需要的操作,例如当天的消息或新消息列表。

/ etc / profile是一个系统范围的登录配置文件脚本。它在您登录时也会运行一次,但会在用户特定的.bashrc之前为所有用户运行

对于像PATH变量这样的环境,.bashrc或/etc/bash.bashrc是一个好地方,这样您就不必担心登录或非登录shell。

这个页面有一些细节:ssh user@host cat /etc/hosts


1
投票

.bash_profile是登录shell的全局配置(交互式或非交互式),.bash_profile是登录shell的每用户配置,http://stefaanlippens.net/bashrc_and_others是交互式非登录shell的配置。

来自/etc/profile

调用

[...]

当bash作为交互式登录shell或作为具有--login选项的非交互式shell调用时,它首先从文件/ etc / profile中读取并执行命令(如果该文件存在)。在读取该文件之后,它按顺序查找〜/ .bash_profile,〜/ .bash_login和〜/ .profile,并从存在且可读的第一个命令中读取并执行命令。启动shell以禁止此行为时,可以使用--noprofile选项。

[...]

当启动不是登录shell的交互式shell时,如果该文件存在,bash将从〜/ .bashrc读取并执行命令。使用--norc选项可以禁止此操作。 --rcfile文件选项将强制bash从文件而不是〜/ .bashrc读取和执行命令。

© www.soinside.com 2019 - 2024. All rights reserved.