Previous Page | Next Page

  1. Introduction
  2. Boot Process
  3. Init and System Initialization
  4. rc.sysinit script
  5. rc script
  6. functions script
  7. Services
  8. apm daemon
  9. network startup
  10. The network script file
  11. The network-functions file
  12. Portmap startup
  13. Random initialization
  14. Syslog initialization
  15. Gated
  16. Atd
  17. cron initialization
  18. pcmcia
  19. inetd daemon
  20. named daemon
  21. lpd daemon
  22. mars-nwe
  23. netfs startup
  24. dhcpd daemon
  25. autofs daemon
  26. keytable daemon
  27. sendmail daemon
  28. gpm daemon
  29. httpd daemon
  30. xfs startup
  31. smb startup
  32. innd startup
  33. linuxconf startup
  34. rc.local script
  35. Init, Getty, Login
  36. The shell
  37. Shutting down
  38. X
  39. Conclusions
  40. App A. rc.sysinit listing
  41. App B. functions listing
  42. App C. rc listing
  43. Credits

Linux Bash

For login shells:

On login (subject to the –noprofile) option),
if "/etc/profile" exists, source it. 
If "~/.bash_profile" exists, source it,
 	else if "~/.bash_login" exists, source it,
 else if "~/.profile" exists, source it.
	On exit, if "~/.bash_logout" exists, source it.

For non-login interactive shells:

	On startup (subject to the –norc and –rcfile options) if "~/.bashrc" exists, source it.

Scripts run from Bash

profile script

Therefore the first file is the "/etc/profile" file (example for my system shown below):

1	# /etc/profile
2
3	# System wide environment and startup programs
4	# Functions and aliases go in /etc/bashrc
5
6	PATH="$PATH:/usr/X11R6/bin"
7	PS1="[\u@\h \w]\\$ "
8
9	ulimit -c 1000000
10	if [ `id -gn` = `id -un` -a `id -u` -gt 14 ]; then
11		umask 002
12	else
13		umask 022
14	fi
15
16	USER=`id -un`
17	LOGNAME=$USER
18	MAIL="/var/spool/mail/$USER"
19	
20	HOSTNAME=`/bin/hostname`
21	HISTSIZE=1000
22	HISTFILESIZE=1000
23
24	INPUTRC=/etc/inputrc
25	export PATH PS1 HOSTNAME HISTSIZE HISTFILESIZE USER LOGNAME MAIL INPUTRC
26
27	for i in /etc/profile.d/*.sh ; do
28		if [ -x $i ]; then
29			. $i
30		fi
31	done
32
33	unset I

Line 6 adds the directory "/usr/X11R6/bin" to the current path. Please note that up till this time I have been unable to track a clear development for the string path that is controllable by the user since many script files change it and some export it to the system. Many of these script files are: "/etc/rc.d/init.d/functions", "/etc/rc.d/init.d/nfs", "/etc/rc.d/init.d/routed", "/etc/rc.d/init.d/squid", "/etc/rc.d/rc", "/etc/rc.d/rc.sysinit" along with many others which may vary depending on the services you run on your system. Note: It may be login that has the effect of setting the path. Therefore my suggestion is that the reader, as system administrator, decide the best way to set the path up and do it in the "/etc/profile" file with a command that does not carry over previous path statements (leave out "$PATH:" as part of the command). Line 7 sets up the bash prompt to output the "username@hostname \currentdirectory". Line 9 limits the size of core files created. Lines 10 through 14 set the file creation mask by using the "id" program to check for matches between the group and user id. On line 16, the user ID is set by using the "id" program to get the user name. On lines 27 through 31 all the script files ending in ".sh" are run. On my system it includes "kde.sh", "lang.sh", and "mc.sh". They are listed below:

KDE.SH:
1	# KDE initialization script (sh)
2	if [ -z "$KDEDIR"  -o  "$KDEDIR" != "/usr" ] ; then
3		KDEDIR="/usr"
4		PATH="$KDEDIR/bin:$PATH"
5	fi
6	export  KDEDIR PATH
LANG.SH:
1	#!/bin/bash
2	
3	if [ -f /etc/sysconfig/i18n ]; then
4	    . /etc/sysconfig/i18n
5	    [ -n "$LANG" ] && export LANG || unset LANG
6	    [ -n "$LC_CTYPE" ] && export LC_CTYPE || unset LC_CTYPE
7	    [ -n "$LC_COLLATE" ] && export LC_COLLATE || unset LC_COLLATE
8	    [ -n "$LC_MESSAGES" ] && export LC_MESSAGES || unset LC_MESSAGES
9	    [ -n "$LC_NUMERIC" ] && export LC_NUMERIC || unset LC_NUMERIC
10	    [ -n "$LC_MONETARY" ] && export LC_MONETARY || unset LC_MONETARY
11	    [ -n "$LC_TIME" ] && export LC_TIME || unset LC_TIME
12	    [ -n "$LC_ALL" ] && export LC_ALL || unset LC_ALL
13	    [ -n "$LANGUAGE" ] && export LANGUAGE || unset LANGUAGE
14	    [ -n "$LINGUAS" ] && export LINGUAS || unset LINGUAS
15
16	    # deprecated
17	    if [ -n "$SYSTERM" ]; then
18		export TERM=$SYSTERM
19	    fi
20
21	    if [ -n "$SYSFONTACM" ]; then
22	        case $SYSFONTACM in
23		   iso01*|iso02*|iso15*|koi*)
24		        LESSCHARSET=latin1
25			export LESSCHARSET INPUTRC
26			if [ "$TERM" = "linux" ]; then
27			    if ls -l /proc/$$/fd/0 2>/dev/null | grep -- '-> /dev/tty[0-9]*$' >/dev/null 2>&1; then
28			echo -n -e '\033(K' > /proc/$$/fd/0
29			    fi
30			fi
31			;;
32	       esac
33	    fi
34  
35	    if [ -n "$INPUTRC" ]; then
36	        export INPUTRC
37	    fi
38  
39	    if [ -n "$LESSCHARSET" ]; then
40	        export LESSCHARSET
41	    elif [ "$TERM" = "linux-lat" ]; then
42	        LESSCHARSET=latin1
43		export LESSCHARSET
44	    fi
45  
46	    [ -n "$_XKB_CHARSET" ] && export _XKB_CHARSET || unset _XKB_CHARSET
47
48	    unset SYSFONTACM
49	fi

MC.SH:
1	mc ()
2	{
3		MC=/tmp/mc$$-"$RANDOM"
4		/usr/bin/mc -P "$@" > "$MC"
5		cd "`cat $MC`"
6		rm "$MC"
7	        unset MC;
8	}

.bash_profile or .bash_login or .profile

The second file run by bash is the ".bash_profile" script file in the users home directory if it exists, else ".bash_login", else ".profile". In my case this is ".bash_profile" listed below:

1	# .bash_profile
2
3	# Get the aliases and functions
4	if [ -f ~/.bashrc ]; then
5	        . ~/.bashrc
6	fi
7
8	# User specific environment and startup programs
9
10	PATH=$PATH:$HOME/bin
11	ENV=$HOME/.bashrc
12	USERNAME="root"
13
14	export USERNAME ENV PATH
15
16	mesg n

On line 5, above, the users ".bashrc" file is run.

1	# .bashrc
2
3	# User specific aliases and functions
4
5	alias rm='rm -i'
6	alias cp='cp -i'
7	alias mv='mv -i'
8
9	# Source global definitions
10	if [ -f /etc/bashrc ]; then
11		. /etc/bashrc
12	fi

This file sets some alias' and runs "/etc/bashrc", listed below.

1	# /etc/bashrc
2
3	# System wide functions and aliases
4	# Environment stuff goes in /etc/profile
5
6	# For some unknown reason bash refuses to inherit
7	# PS1 in some circumstances that I can't figure out.
8	# Putting PS1 here ensures that it gets loaded every time.
9	PS1="[\u@\h \w]\\$ "

All this file does is set the bash prompt up again. Note that in order for any changes to the bash prompt to be effective from startup, (because of this) the changes must be made here as well as in "/etc/profile" or any other files.

~/.bash_logout

1	# ~/.bash_logout
2	
3	clear