auf.kante
Gunnar macht sich selbststaendig und fliegt auf
die Schnauze
wird erfolgreich. Wer mag darf zuschauen.
Gunnar is starting his business. He will certainly
fail succeed. You may watch.
auf.kante
Website sections
Home
Login startup files
Last changed: 2005-08-27 [13:45]
Content:

Notes on bash startup
 
Back to Personal Wiki
Table of contents
Starting bash
/etc/profile
~/.bashrc
~/.bash_profile

Starting bash

The startup files that will be executed on bash startup depend on two factors: whether bash is started as a login or non-login shell and whether it is started in interactive or non-interactive mode.

If you login to bash (or use the --login option) the shell will always read /etc/profile, followed by ~/.bash_profile.

If you start bash as a non-login shell, the script ~/.bashrc will get executed.

Non-interactive shells won't execute any scripts as long as you do not set a filename in BASH_ENV.

There are more variants to these basic variants but for a standard gentoo system, these are the situations that are relevant.

/etc/profile

This script should handle all settings that are necessary on login and that are only necessary once. This is the first script that gets executed.

The following sections describe the tasks handled by my profile script (which is derived from the standard Gentoo script).

Loginshell

# Signifies that this is a login shell
loginshell=yes

I set this variable so that any subsequent script can use it to verify whether this is a login shell or not. There are probably also other ways to determine that.

if [ -e "/etc/profile.env" ]; then
	. /etc/profile.env
fi

Loads in all necessary environment settings. Standard Gentoo procedure.

[ -z "$EDITOR" ] && EDITOR="`. /etc/rc.conf 2>/dev/null; echo $EDITOR`"
[ -z "$EDITOR" ] && EDITOR="/bin/nano"
export EDITOR

Extracts the editor setting from /etc/rc.conf and defaults to nano, the default Gentoo editor.

# Set the inputrc file
if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]
then
        export INPUTRC="/etc/inputrc"
fi

Sets the location of the inputrc file.

if [ "$EUID" = 0 ] || [ "`/bin/whoami`" = 'root' ]; then
	PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${ROOTPATH}"
else
	PATH="/usr/local/bin:/usr/bin:/bin:${PATH}"
	if [ -d "$HOME/bin" ]
	    then
	    PATH="$HOME/bin:${PATH}"
	fi
fi
export PATH
unset ROOTPATH

Configures the path for normal as well as root users. In addition to standard Gentoo procedures I add ~/bin to the path in case it exists.

umask 022

Setting a proper umask.

trap 'test -n "$SSH2_AGENT_PID" && kill $SSH2_AGENT_PID' 0

If there are still ssh agents hanging around they are killed on logout.

if [ -f /etc/bash/bash-interactive ]; then
    . /etc/bash/bash-interactive
fi

A login shell is also interactive, so we setup the interactive features here.

~/.bashrc

This will be called by all interactive, non-login shells.

if [ -f /etc/bash/bash-interactive ]; then
    . /etc/bash/bash-interactive
fi

Configure the interactive features.

if [ -f ~/.bash-interactive ]; then
    . ~/.bash-interactive
fi

This finalizes prompt setup and selects the locale by sourcing ~/.bash-interactive

~/.bash_profile

This will be called by login shells after /etc/profile.

if [ -f ~/.bash-interactive ]; then
    . ~/.bash-interactive
fi

Same as ~/.bashrc

Back to Personal Wiki
Creative Commons-Lizenzvertrag
The content of this site is licensed under a Creative Commons 2.5 License [attribution, share-alike]