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
|