29 May 2012 yeupou   » (Master)

Having homemade aliases, functions and such available to every interactive shells,

Years ago, I remember RedHat already provided /etc/bashrc.d/ to add custom scripts to be sourced site-wide whenever bash was started. Debian still only provides /etc/profile.d for such scripts to be sourced site-wide. So, starting using Debian, I added stuff in this latest directory and made sure that /etc/bash.bashrc itself ran /etc/profile so it would be sourced in any cases.

There is actually a problem with that.

As defined (RTFM! `man bash`), /etc/profile is to be sourced for interactive login shells (`bash –login`) while /etc/bashrc or /etc/bash.bashrc is to be sourced for interactive non-login shells (`bash`). Having /etc/profile ran by /etc/bash.bashrc defeats the overal purpose of distinguishing the two of them. LFS ask for /etc/profile content to be a run-once thing, for logins, not something that should be started for any xterm.

But if you don’t, anything in /etc/profile.d will be ignored by most shells you’ll start on a X session, where you actually log in once and then starts numerous xterms. Ok, to put your aliases and local functions, you can edit /etc/bash.bashrc and use skels for ~/.bashrc, but that’s way less convenient than just copying a script into a directory.

To get something consistent, I added the /etc/bashrc.d directory. I think such directory should exists by default on Debian, even if I would agree if someone was to point out that this should not be BASH-specific.

Here’s an example of my /etc/bashrc.d and my /etc/profile.d. My local debian package postinst script add automatically the required following line in /etc/bash.bashrc:

[ -z "$ETC_BASHRC_SOURCED" ] && for i in /etc/bashrc.d/*.sh ; do if [ -r "$i" ]; then . $i; fi; done

Note that the same postinst script symlink /etc/profile.d/bash_completion.sh to /etc/bashrc.d/bash_completion.sh. The very existence of this file in /etc/profile.d IMHO show the extent of the broken default design. How come someone would actually want bash completion for login shells but not for interactive non-login shells? I would actually expect the contrary: as bash completion can be CPU time consuming, if it is to be skipped in only one case, it’s definitely on login shells! Why is it so? Probably because only /etc/profile.d exists.

(I’ve read also some people saying that /etc/bash.bashrc should be edited by hand. On any computers of a local network just to add a few local aliases? Ouch!)

Syndicated 2012-05-29 09:45:35 from # cd /scratch

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!