5 | | <para>NEW PAGE TO BE WRITTEN</para> |
| 5 | <para>The shell program <filename>/bin/bash</filename> (hereafter |
| 6 | refered to as just "the shell") uses a collection of startup files to |
| 7 | help create an environment to run in. Each file has a specific use and |
| 8 | non-login, and non-interactive.</para> |
| 9 | |
| 10 | <para>An interactive login shell is started after a successful login by |
| 11 | <filename>/bin/login</filename> by reading the /etc/passwd file. An |
| 12 | interactive non-login shell is started at the command line (e.g. |
| 13 | [prompt]$<userinput>/bin/bash</userinput>). A non-interactive shell is |
| 14 | usually present when a shell script is running. It is non-interactive |
| 15 | because it is processing a script and not waiting for user input between |
| 16 | commands.</para> |
| 17 | |
| 18 | <para>For more information see <filename>info bash</filename> -- Nodes: |
| 19 | Bash Startup Files and Interactive Shells</para> |
| 20 | |
| 21 | <para>The following files are needed to make sure that the correct |
| 22 | environment is read for each of the ways the shell can be invoked: |
| 23 | <filename>/etc/profile</filename>, <filename>/etc/bashrc</filename>, |
| 24 | <filename>~/.bash_profile</filename>, and |
| 25 | <filename>~/.bashrc</filename>. The file |
| 26 | <filename>~/.bash_logout</filename> is not used for an invokation of the |
| 27 | shell. It is read by the shell when a user logouts of the system. The |
| 28 | files <filename>/etc/profile</filename> and |
| 29 | <filename>~/.bash_profile</filename> are read when the shell is invoked |
| 30 | as a interactive login shell. The file <filename>~/.bashrc</filename> |
| 31 | is read when the shell is invoked as an interactive non-login |
| 32 | shell.</para> |
| 33 | |
| 34 | <para>Here is a base <filename>/etc/profile</filename>.</para> |
| 35 | |
| 36 | <para><screen> |
| 37 | # Begin /etc/profile |
| 38 | # Written for Beyond Linux From Scratch |
| 39 | # by James Robertson <jameswrobertson@earthlink.net> |
| 40 | |
| 41 | # System wide environment variables and startup programs. |
| 42 | |
| 43 | # System wide aliases and functions should go in /etc/bashrc. Personal |
| 44 | # environment variables and startup programs should go into |
| 45 | # ~/.bash_profile. Personal aliases and functions should go into |
| 46 | # ~/.bashrc. |
| 47 | |
| 48 | # Function to help us mangage paths |
| 49 | pathman () { |
| 50 | if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then |
| 51 | if [ "$2" = "last" ] ; then |
| 52 | PATH=$PATH:$1 |
| 53 | else |
| 54 | PATH=$1:$PATH |
| 55 | fi |
| 56 | fi |
| 57 | } |
| 58 | |
| 59 | # Add to the standard path. |
| 60 | if [ $(id -u) = 0 ] ; then |
| 61 | if [ -d "/usr/local/sbin" ] ; then |
| 62 | pathman /usr/local/sbin last |
| 63 | fi |
| 64 | fi |
| 65 | |
| 66 | if [ $(id -u) != 0 ] ; then |
| 67 | if [ -d "/usr/local/bin" ] ; then |
| 68 | pathman /usr/local/bin last |
| 69 | fi |
| 70 | fi |
| 71 | |
| 72 | if [ -d "/usr/X11R6/bin" ] ; then |
| 73 | pathman /usr/X11R6/bin last |
| 74 | fi |
| 75 | |
| 76 | # Setup some environment variables. |
| 77 | USER=$(id -un) |
| 78 | LOGNAME=$USER |
| 79 | MAIL="/var/mail/$USER" |
| 80 | HOSTNAME=$(/bin/hostname) |
| 81 | HISTSIZE=1000 |
| 82 | PS1="[\u@\h \w]\\$ " |
| 83 | |
| 84 | # Setup the INPUTRC environment variable. |
| 85 | if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ] ; then |
| 86 | INPUTRC=/etc/inputrc |
| 87 | fi |
| 88 | |
| 89 | # Setup for /bin/ls to support color, the alias is in /etc/bashrc. |
| 90 | if [ -f "/etc/dircolors" ] ; then |
| 91 | eval $(dircolors -b /etc/dircolors) |
| 92 | |
| 93 | if [ -f "$HOME/.dircolors" ] ; then |
| 94 | eval $(dircolors -b $HOME/.dircolors) |
| 95 | fi |
| 96 | fi |
| 97 | |
| 98 | export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE PS1 LS_COLORS INPUTRC |
| 99 | |
| 100 | # End /etc/profile |
| 101 | </screen></para> |
| 102 | |
| 103 | |
| 104 | <para>Here is a base <filename>/etc/bashrc</filename>. Comments in the |
| 105 | file should explain everything you need.</para> |
| 106 | |
| 107 | <para><screen> |
| 108 | # Begin /etc/bashrc |
| 109 | # Written for Beyond Linux From Scratch |
| 110 | # by James Robertson <jameswrobertson@earthlink.net> |
| 111 | |
| 112 | # System wide aliases and functions. |
| 113 | |
| 114 | # System wide environment variables and startup programs should go into |
| 115 | # /etc/profile. Personal environment variables and startup programs |
| 116 | # should go into ~/.bash_profile. Personal aliases and functions should |
| 117 | # go into ~/.bashrc |
| 118 | |
| 119 | # By default we want the umask to get set. |
| 120 | # Even for non-interactive and non-login shells. |
| 121 | if [ "$(id -gn)" = "$(id -un)" -a $(id -u) -gt 99 ] ; then |
| 122 | umask 002 |
| 123 | else |
| 124 | umask 022 |
| 125 | fi |
| 126 | |
| 127 | # Provides a colored /bin/ls command. Used in conjunction with code in |
| 128 | # /etc/profile. |
| 129 | alias ls='ls --color=auto' |
| 130 | |
| 131 | # End /etc/bashrc |
| 132 | </screen></para> |
| 133 | |
| 134 | <para>Here is a base <filename>~/.bash_profile</filename>. Comments in |
| 135 | the file should explain everything you need.</para> |
| 136 | |
| 137 | <para><screen> |
| 138 | # Begin ~/.bash_profile |
| 139 | # Written for Beyond Linux From Scratch |
| 140 | # by James Robertson <jameswrobertson@earthlink.net> |
| 141 | |
| 142 | # Personal envrionment variables and startup programs. |
| 143 | |
| 144 | # Personal aliases and functions should go in ~/.bashrc. System wide |
| 145 | # environment variables and startup programs are in /etc/profile. |
| 146 | # System wide aliases and functions are in /etc/bashrc. |
| 147 | |
| 148 | if [ -f "$HOME/.bashrc" ] ; then |
| 149 | . $HOME/.bashrc |
| 150 | fi |
| 151 | |
| 152 | if [ -d "$HOME/bin" ] ; then |
| 153 | pathman $HOME/bin last |
| 154 | fi |
| 155 | |
| 156 | export PATH |
| 157 | |
| 158 | # End ~/.bash_profile |
| 159 | </screen></para> |
| 160 | |
| 161 | <para>Here is a base <filename>~/.bashrc</filename>. Comments in the |
| 162 | file should explain everything you need.</para> |
| 163 | |
| 164 | <para><screen> |
| 165 | # Begin ~/.bashrc |
| 166 | # Written for Beyond Linux From Scratch |
| 167 | # by James Robertson <jameswrobertson@earthlink.net> |
| 168 | |
| 169 | # Personal aliases and functions. |
| 170 | |
| 171 | # Personal environment variables and startup programs should go in |
| 172 | # ~/.bash_profile. System wide environment variables and starup |
| 173 | # programs are in /etc/profile. System wide aliases and functions are |
| 174 | # in /etc/bashrc. |
| 175 | |
| 176 | if [ -f "/etc/bashrc" ] ; then |
| 177 | . /etc/bashrc |
| 178 | fi |
| 179 | |
| 180 | # End ~/.bashrc |
| 181 | </screen></para> |
| 182 | |
| 183 | <para>Here is a base <filename>~/.bash_logout</filename>. Comments in |
| 184 | the file should explain everything you need.</para> |
| 185 | |
| 186 | <para><screen> |
| 187 | # Begin ~/.bash_logout |
| 188 | # Written for Beyond Linux From Scratch |
| 189 | # by James Robertson <jameswrobertson@earthlink.net> |
| 190 | |
| 191 | # Personal items to perform on logout. |
| 192 | |
| 193 | # End ~/.bash_logout |
| 194 | </screen></para> |
| 195 | |
| 196 | <para>If you want to use the <filename>/etc/dircolors</filename> or |
| 197 | <filename>~/.dircolors</filename> files called from |
| 198 | <filename>/etc/profile</filename>, then run the following: |
| 199 | <userinput>/bin/dircolors -p > /etc/dircolors</userinput> or |
| 200 | <userinput>/bin/dircolors -p > ~/.dircolors</userinput> respectively. |
| 201 | The file in the <filename>/etc</filename> directory should be used for |
| 202 | global settings and if one exists in your home directory then it will |
| 203 | overwrite the global settings. It might be a good idea to create a base |
| 204 | <filename>.dircolors</filename> file and place it in the |
| 205 | <filename>/etc/skel</filename> directory for new users.</para> |