Bash Configuration Files: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(10 intermediate revisions by the same user not shown)
Line 7: Line 7:


* [[Bash#Subjects|bash]]
* [[Bash#Subjects|bash]]
* [[PATH]]


=Overview=
=Overview=
This article describes how bash executes its startup files. If any of the files exist, but cannot be read, bash reports an error.
This article describes how bash executes its startup files. If any of the files exist, but cannot be read, bash reports an error.
=Interactive Login Shell=
=Interactive Login Shell=
This sequence is executed by an interactive login shell, or a shell that was invoked with <code>--login</code>:
<font size=-1>
<font size=-1>
  [[/etc/profile]]
  ├─→ [[/etc/profile]] ─→ /etc/profile.d/*.sh
└─→ ~/.bash_profile ─→ ~/.bash_login ─→ ~/.profile <font color=teal># executes the first one that exists and it is readable</font>
</font>
 
<font color=darkgray>When more than one of <code>~/.bash_profile</code>, <code>~/.bash_login</code> or <code>~/.profile</code> exists and it is readable, the first one, in this order, is executed.</font>
 
<font size=-1>
  ~/[[.bashrc]]
</font>
 
 
 
<font color=darkkhaki>TODO:
 
* https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html
* https://stackoverflow.com/a/26962251
</font>
</font>


Line 26: Line 46:
=Invoked by Remote Shell Daemon=
=Invoked by Remote Shell Daemon=
=Invoked with Unequal Effective and Real UID/GIDs=
=Invoked with Unequal Effective and Real UID/GIDs=
=Setting Configuration for all Users, Including <tt>root</tt>=
To set up shell configuration system-wide, either update <code>[[/etc/profile]]</code> or add a specialized <code>/etc/profile./d/*.sh</code> file, which is automatically executed when <code>[[/etc/profile]]</code> is evaluated.
<font color=darkkhaki>
Found this comment in <code>/etc/profile</code>:
<syntaxhighlight lang='text'>
                # Bash login shells run only /etc/profile
                # Bash non-login shells run only /etc/bashrc
</syntaxhighlight>
</font>

Latest revision as of 06:57, 4 May 2022

External

Internal

Overview

This article describes how bash executes its startup files. If any of the files exist, but cannot be read, bash reports an error.

Interactive Login Shell

This sequence is executed by an interactive login shell, or a shell that was invoked with --login:

├─→ /etc/profile ─→ /etc/profile.d/*.sh
│
│
└─→ ~/.bash_profile ─→ ~/.bash_login ─→ ~/.profile # executes the first one that exists and it is readable

When more than one of ~/.bash_profile, ~/.bash_login or ~/.profile exists and it is readable, the first one, in this order, is executed.

 ~/.bashrc


TODO:

Interactive Non-Login Shell

Non-Interactive Shell

Invoked with the name "sh"

Invoked by Remote Shell Daemon

Invoked with Unequal Effective and Real UID/GIDs

Setting Configuration for all Users, Including root

To set up shell configuration system-wide, either update /etc/profile or add a specialized /etc/profile./d/*.sh file, which is automatically executed when /etc/profile is evaluated.

Found this comment in /etc/profile:

                # Bash login shells run only /etc/profile
                # Bash non-login shells run only /etc/bashrc