You are not logged in.

#1 2012-06-09 21:36:36

mloskot
Member
From: London, United Kingdom
Registered: 2012-06-01
Posts: 86
Website

[Bash] Configuration file sourcing order at startup - confusing

Hi,

I have noticed the section "Configuration file sourcing order" (at startup) of the Bash article is confusing.
There is some discussion to this article requesting to clarify the startup procedure too.

There are two subsections of this section:

1. Generic part starting with "These files are sourced..."

The second top-level bullet of generic section is:

if interactive + non-login shell → /etc/bash.bashrc then ~/.bashrc

Where does the reference to /etc/bash.bashrc file come from?
The Bash manual does not say anything about this file.
Is this Arch-specific?

IMO, this bullet should read simply:

if interactive + non-login shell → ~/.bashrc

2. Arch-specific starting with "But, in Arch, by default..."

It should be stated it is Arch-specific and the I'd propose to stick to the A + B  → C convention.

The second bullet is possibly confusing due to lack of paranthesis:

/etc/skel/.bash_profile (which users are encouraged to copy to ~/.bash_profile) sources ~/.bashrc
which means that /etc/bash.bashrc and ~/.bashrc will be executed

But, why not to stick to the convention above and change it to:

/etc/skel/.bash_profile → ~/.bashrc
which means that /etc/bash.bashrc and ~/.bashrc will be executed (...).

Users are encouraged to copy /etc/skel/.bash_profile to ~/.bash_profile.

Simply, the current version tries to interleave and inject too many things within single statement.

IMHO, that would make things clearer.


Mateusz Loskot | github | archlinux-config
Arch (x86-64) | ThinkPad T400  | Intel P8600| Intel i915
Arch (x86-64) | ThinkPad W700 | Intel T9600 | NVIDIA Quadro FX 2700M

Offline

#2 2012-06-09 23:41:17

thisoldman
Member
From: Pittsburgh
Registered: 2009-04-25
Posts: 1,172

Re: [Bash] Configuration file sourcing order at startup - confusing

mloskot wrote:

if interactive + non-login shell → /etc/bash.bashrc then ~/.bashrc

Where does the reference to /etc/bash.bashrc file come from?
The Bash manual does not say anything about this file.
Is this Arch-specific?

The /etc/bash.bashrc file is sourced by /etc/profile.  Other shells also read /etc/profile – bash.bashrc provides just a few sane system-wide defaults for that particular shell.

Debian, Ubuntu and Suse have used /etc/bash.bashrc in the past; I don't know that they still use it.  I've also seen references to distros using /etc/bashrc and /etc/bash/bashrc.

I guess the answer is that use of /etc/bash.bashrc is common, other distros may use a similar resource file but give it a different name.  A naked install of bash from source would not expect or require this file.

Edited for, I hope, more clarity.

Last edited by thisoldman (2012-06-09 23:46:00)

Offline

#3 2012-06-10 00:56:37

mloskot
Member
From: London, United Kingdom
Registered: 2012-06-01
Posts: 86
Website

Re: [Bash] Configuration file sourcing order at startup - confusing

thisoldman wrote:

I guess the answer is that use of /etc/bash.bashrc is common

Yes, I've researched about it quickly and I can confirm it is nothing specific to Arch.

Simply, the Bash manual is lacking information about the/etc/bash.bashrc as system-wide configuration version of ~/.bashrc file:

$ find . -type f | xargs grep -C 1 'bash.bashrc'
./config-top.h-/* System-wide .bashrc file for interactive shells. */
./config-top.h:/* #define SYS_BASHRC "/etc/bash.bashrc" */
./config-top.h-

In shell.c, there is flag defined:

static int no_rc;			/* Don't execute ~/.bashrc */

which later is used to decide if /etc/bash.bashrc (provided by SYS_BASHRC) is sourced from the dedicated function:

static void
run_startup_files ()
{
...
      /* bash */
      if (act_like_sh == 0 && no_rc == 0)
	{
#ifdef SYS_BASHRC
#  if defined (__OPENNT)
	  maybe_execute_file (_prefixInstallPath(SYS_BASHRC, NULL, 0), 1);
#  else
	  maybe_execute_file (SYS_BASHRC, 1);
#  endif
#endif
	  maybe_execute_file (bashrc_file, 1);
	}
...
}

It seems /etc/bash.bashrc is ru nautomatically on startup, if found and if the relevant flags are set, but not necessarily only if sourced from /etc/profile file. It could be clarified anyway.

Also, I found citation from the "Ubuntu Certified Professional Study Guide" by Michael Jang, the following were the points given in that book about function of /etc/bash.bashrc file:

* It assigns a prompt, which is what you see just before the cursor at the command prompt.
* It includes settings from /etc/bash_completion to enable command completion.
* It configures messages associated with sudo access; for more information.

But perhaps that's something more Ubuntu-specific now smile

Anyhow, I'd still suggest to update the Wiki as mentioned above, even if there is nothing Arch-specific.


Mateusz Loskot | github | archlinux-config
Arch (x86-64) | ThinkPad T400  | Intel P8600| Intel i915
Arch (x86-64) | ThinkPad W700 | Intel T9600 | NVIDIA Quadro FX 2700M

Offline

Board footer

Powered by FluxBB