[f8d632ac] | 1 | <?xml version="1.0" encoding="ISO-8859-1"?>
|
---|
| 2 | <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
|
---|
| 3 | "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
|
---|
| 4 | <!ENTITY % general-entities SYSTEM "../../general.ent">
|
---|
| 5 | %general-entities;
|
---|
| 6 | ]>
|
---|
| 7 |
|
---|
[78b3cd61] | 8 | <sect1 id="postlfs-config-profile" xreflabel="The Bash Shell Startup Files">
|
---|
[bae6e15] | 9 | <?dbhtml filename="profile.html"?>
|
---|
[b554263] | 10 | <title>The Bash Shell Startup Files</title>
|
---|
[f45b1953] | 11 |
|
---|
[b554263] | 12 | <para>The shell program <filename>/bin/bash</filename> (hereafter
|
---|
[64d97b7c] | 13 | referred to as just "the shell") uses a collection of startup files to
|
---|
[1a396398] | 14 | help create an environment. Each file has a specific use and
|
---|
[cfc2a54] | 15 | may affect login and interactive environments differently. The files in
|
---|
[8604d92f] | 16 | the <filename class="directory">/etc</filename> directory generally provide global
|
---|
[cfc2a54] | 17 | settings. If an equivalent file exists in your home directory it may
|
---|
| 18 | override the global settings.
|
---|
| 19 | </para>
|
---|
| 20 |
|
---|
| 21 | <para>An interactive login shell is started after a successful login, using
|
---|
[1a396398] | 22 | <filename>/bin/login</filename>, by reading the <filename>/etc/passwd</filename>
|
---|
| 23 | file. This shell invocation normally reads <filename>/etc/profile</filename>
|
---|
| 24 | and its private equivalent <filename>~/.bash_profile</filename> upon startup.</para>
|
---|
| 25 |
|
---|
| 26 | <para>An interactive non-login shell is normally started at the command-line
|
---|
[0990cf7a] | 27 | (e.g., <prompt>[prompt]$</prompt><command>/bin/bash</command>) or by the
|
---|
[1a396398] | 28 | <command>/bin/su</command> command. An interactive non-login shell is also
|
---|
| 29 | started with a terminal program such as <command>xterm</command> or
|
---|
| 30 | <command>konsole</command> from within a graphical environment. This type of
|
---|
| 31 | shell invocation normally copies the parent environment and then reads the
|
---|
| 32 | user's <filename>~/.bashrc</filename> file for additional startup configuration
|
---|
| 33 | instructions.</para>
|
---|
| 34 |
|
---|
| 35 | <para>A non-interactive shell is usually present when a shell script is
|
---|
| 36 | running. It is non-interactive because it is processing a script and not
|
---|
[3b7081ba] | 37 | waiting for user input between commands. For these shell invocations, only
|
---|
| 38 | the environment inherited from the parent shell is used.</para>
|
---|
[1a396398] | 39 |
|
---|
| 40 | <para> The file <filename>~/.bash_logout</filename> is not used for an
|
---|
| 41 | invocation of the shell. It is read and executed when a user exits from an
|
---|
| 42 | interactive login shell.</para>
|
---|
| 43 |
|
---|
| 44 | <para>To the standard files, we also add <filename>/etc/bashrc</filename>
|
---|
| 45 | which is called from the user's <filename>~/.bashrc</filename> for
|
---|
| 46 | system wide initialization of non-login shells.</para>
|
---|
[b554263] | 47 |
|
---|
[766bbe40] | 48 | <para>For more information see <command>info bash</command> --
|
---|
| 49 | <emphasis role="strong">Nodes: Bash Startup Files and Interactive
|
---|
| 50 | Shells.</emphasis></para>
|
---|
[b554263] | 51 |
|
---|
[1a396398] | 52 | <sect2>
|
---|
| 53 | <title><filename>/etc/profile</filename></title>
|
---|
[cfc2a54] | 54 |
|
---|
[1a396398] | 55 | <para>Here is a base <filename>/etc/profile</filename>. This file starts by
|
---|
| 56 | setting up some helper functions and some basic parameters. It specifies some
|
---|
| 57 | <filename>bash</filename> history parameters and, for security purposes,
|
---|
| 58 | disables keeping a permanent history file for the root user. It also sets a
|
---|
| 59 | default user prompt. It then calls small, single purpose scripts in the
|
---|
| 60 | <filename class='directory'>/etc/profile.d</filename> directory to provide most
|
---|
| 61 | initialization. </para>
|
---|
[b554263] | 62 |
|
---|
[1a396398] | 63 | <para>For more information on the escape sequences you can use for your prompt
|
---|
[0990cf7a] | 64 | (e.g., the <envar>PS1</envar> environment variable) see <command>info
|
---|
[766bbe40] | 65 | bash</command> -- <emphasis role="strong">Node: Printing a
|
---|
| 66 | Prompt.</emphasis></para>
|
---|
[b554263] | 67 |
|
---|
[766bbe40] | 68 | <screen><userinput><command>cat > /etc/profile << "EOF"</command>
|
---|
| 69 | # Begin /etc/profile
|
---|
[b554263] | 70 | # Written for Beyond Linux From Scratch
|
---|
| 71 | # by James Robertson <jameswrobertson@earthlink.net>
|
---|
[1a396398] | 72 | # modifications by Dagmar d'Surreal <rivyqntzne@pbzpnfg.arg>
|
---|
| 73 |
|
---|
[b554263] | 74 | # System wide environment variables and startup programs.
|
---|
[1a396398] | 75 |
|
---|
[b554263] | 76 | # System wide aliases and functions should go in /etc/bashrc. Personal
|
---|
| 77 | # environment variables and startup programs should go into
|
---|
| 78 | # ~/.bash_profile. Personal aliases and functions should go into
|
---|
| 79 | # ~/.bashrc.
|
---|
[1a396398] | 80 |
|
---|
| 81 | # Functions to help us manage paths. Second argument is the name of the
|
---|
| 82 | # path variable to be modified (default: PATH)
|
---|
| 83 | pathremove () {
|
---|
| 84 | local IFS=':'
|
---|
| 85 | local NEWPATH
|
---|
| 86 | local DIR
|
---|
| 87 | local PATHVARIABLE=${2:-PATH}
|
---|
| 88 | for DIR in ${!PATHVARIABLE} ; do
|
---|
| 89 | if [ "$DIR" != "$1" ] ; then
|
---|
| 90 | NEWPATH=${NEWPATH:+$NEWPATH:}$DIR
|
---|
| 91 | fi
|
---|
| 92 | done
|
---|
| 93 | export $PATHVARIABLE="$NEWPATH"
|
---|
[b554263] | 94 | }
|
---|
[1a396398] | 95 |
|
---|
| 96 | pathprepend () {
|
---|
| 97 | pathremove $1 $2
|
---|
| 98 | local PATHVARIABLE=${2:-PATH}
|
---|
| 99 | export $PATHVARIABLE="$1${!PATHVARIABLE:+:${!PATHVARIABLE}}"
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | pathappend () {
|
---|
| 103 | pathremove $1 $2
|
---|
| 104 | local PATHVARIABLE=${2:-PATH}
|
---|
| 105 | export $PATHVARIABLE="${!PATHVARIABLE:+${!PATHVARIABLE}:}$1"
|
---|
| 106 | }
|
---|
| 107 |
|
---|
[e9ef7b5e] | 108 |
|
---|
| 109 | # Set the initial path
|
---|
| 110 | export PATH=/bin:/usr/bin
|
---|
| 111 |
|
---|
[1a396398] | 112 | if [ $EUID -eq 0 ] ; then
|
---|
[e9ef7b5e] | 113 | pathappend /sbin:/usr/sbin
|
---|
[1a396398] | 114 | unset HISTFILE
|
---|
[b554263] | 115 | fi
|
---|
[1a396398] | 116 |
|
---|
| 117 | # Setup some environment variables.
|
---|
| 118 | export HISTSIZE=1000
|
---|
| 119 | export HISTIGNORE="&:[bf]g:exit"
|
---|
| 120 | #export PS1="[\u@\h \w]\\$ "
|
---|
| 121 | export PS1='\u@\h:\w\$ '
|
---|
| 122 |
|
---|
| 123 | for script in /etc/profile.d/*.sh ; do
|
---|
[d3880c0] | 124 | if [ -r $script ] ; then
|
---|
[1a396398] | 125 | . $script
|
---|
| 126 | fi
|
---|
| 127 | done
|
---|
| 128 |
|
---|
| 129 | # Now to clean up after ourselves
|
---|
| 130 | unset pathremove pathprepend pathappend
|
---|
| 131 |
|
---|
| 132 | # End /etc/profile
|
---|
| 133 | <command>EOF</command></userinput></screen>
|
---|
| 134 |
|
---|
| 135 | <para>Now create the <filename class='directory'>/etc/profile.d</filename> directory.</para>
|
---|
| 136 |
|
---|
| 137 | <screen><userinput><command>install --directory --mode=0755 --owner=root --group=root /etc/profile.d</command></userinput></screen>
|
---|
| 138 |
|
---|
| 139 | <sect3>
|
---|
| 140 | <title><filename>/etc/profile.d/dircolors.sh</filename></title>
|
---|
| 141 |
|
---|
| 142 | <para>This script uses the <filename>~/.dircolors</filename> and
|
---|
| 143 | <filename>/etc/dircolors</filename> files to control the colors of file names in a
|
---|
| 144 | directory listing. They control colorized output of things like <command>ls
|
---|
| 145 | --color</command>. The explaination of how to initialize these files is at the
|
---|
| 146 | end of this section. </para>
|
---|
[b554263] | 147 |
|
---|
[1a396398] | 148 |
|
---|
| 149 | <screen><userinput><command>cat > /etc/profile.d/dircolors.sh << "EOF"</command>
|
---|
| 150 | # Setup for /bin/ls to support color, the alias is in /etc/bashrc.
|
---|
| 151 | if [ -f "/etc/dircolors" ] ; then
|
---|
| 152 | eval $(dircolors -b /etc/dircolors)
|
---|
| 153 |
|
---|
| 154 | if [ -f "$HOME/.dircolors" ] ; then
|
---|
| 155 | eval $(dircolors -b $HOME/.dircolors)
|
---|
| 156 | fi
|
---|
[b554263] | 157 | fi
|
---|
[1a396398] | 158 | alias ls='ls --color=auto'
|
---|
| 159 | <command>EOF</command></userinput></screen>
|
---|
| 160 | </sect3>
|
---|
| 161 |
|
---|
[b554263] | 162 |
|
---|
[1a396398] | 163 | <sect3>
|
---|
| 164 | <title><filename>/etc/profile.d/extrapaths.sh</filename></title>
|
---|
| 165 |
|
---|
| 166 | <para>This script adds several useful paths to the <envar>PATH</envar> and
|
---|
| 167 | <envar>PKG_CONFIG_PATH</envar> environment variables. If you want, you can uncomment
|
---|
| 168 | the last section to put a dot at the end of your path. This will allow executables in the
|
---|
[4faa9b91] | 169 | current working directory to be executed without specifiying a ./, however
|
---|
[1a396398] | 170 | you are warned that this is generally considered a security hazard.</para>
|
---|
| 171 |
|
---|
| 172 | <screen><userinput><command>cat > /etc/profile.d/extrapaths.sh << "EOF"</command>
|
---|
| 173 | if [ -d /usr/local/lib/pkgconfig ] ; then
|
---|
| 174 | pathappend /usr/local/lib/pkgconfig PKG_CONFIG_PATH
|
---|
| 175 | fi
|
---|
| 176 | if [ -d /usr/local/bin ]; then
|
---|
| 177 | pathprepend /usr/local/bin
|
---|
[b554263] | 178 | fi
|
---|
[1a396398] | 179 | if [ -d /usr/local/sbin -a $EUID -eq 0 ]; then
|
---|
| 180 | pathprepend /usr/local/sbin
|
---|
| 181 | fi
|
---|
[d3880c0] | 182 | for directory in $(find /opt/*/lib/pkgconfig -type d 2>/dev/null); do
|
---|
[1a396398] | 183 | pathappend $directory PKG_CONFIG_PATH
|
---|
| 184 | done
|
---|
[d3880c0] | 185 | for directory in $(find /opt/*/bin -type d 2>/dev/null); do
|
---|
[1a396398] | 186 | pathappend $directory
|
---|
| 187 | done
|
---|
| 188 | if [ -d ~/bin ]; then
|
---|
| 189 | pathprepend ~/bin
|
---|
| 190 | fi
|
---|
| 191 | #if [ $EUID -gt 99 ]; then
|
---|
| 192 | # pathappend .
|
---|
| 193 | #fi
|
---|
| 194 | <command>EOF</command></userinput></screen>
|
---|
| 195 | </sect3>
|
---|
[b554263] | 196 |
|
---|
[1a396398] | 197 | <sect3>
|
---|
| 198 | <title><filename>/etc/profile.d/readline.sh</filename></title>
|
---|
[b554263] | 199 |
|
---|
[1a396398] | 200 | <para>This script sets up the default <filename>inputrc</filename> configuration file.
|
---|
| 201 | If the user does not have individual settings, it uses the global file.</para>
|
---|
| 202 |
|
---|
| 203 | <screen><userinput><command>cat > /etc/profile.d/readline.sh << "EOF"</command>
|
---|
[b554263] | 204 | # Setup the INPUTRC environment variable.
|
---|
| 205 | if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ] ; then
|
---|
[1a396398] | 206 | INPUTRC=/etc/inputrc
|
---|
[b554263] | 207 | fi
|
---|
[1a396398] | 208 | export INPUTRC
|
---|
| 209 | <command>EOF</command></userinput></screen>
|
---|
| 210 | </sect3>
|
---|
[b554263] | 211 |
|
---|
[1a396398] | 212 | <sect3>
|
---|
| 213 | <title><filename>/etc/profile.d/tinker-term.sh</filename></title>
|
---|
[b554263] | 214 |
|
---|
[1a396398] | 215 | <para>Some applications need a specific <envar>TERM</envar> setting to support color.</para>
|
---|
| 216 |
|
---|
| 217 | <screen><userinput><command>cat > /etc/profile.d/tinker-term.sh << "EOF"</command>
|
---|
| 218 | # This will tinker with the value of TERM in order to convince certain apps
|
---|
| 219 | # that we can, indeed, display color in their window.
|
---|
| 220 |
|
---|
| 221 | if [ -n "$COLORTERM" ]; then
|
---|
| 222 | export TERM=xterm-color
|
---|
| 223 | fi
|
---|
| 224 |
|
---|
| 225 | if [ "$TERM" = "xterm" ]; then
|
---|
| 226 | export TERM=xterm-color
|
---|
[b554263] | 227 | fi
|
---|
[1a396398] | 228 | <command>EOF</command></userinput></screen>
|
---|
| 229 | </sect3>
|
---|
[b554263] | 230 |
|
---|
[1a396398] | 231 | <sect3>
|
---|
| 232 | <title><filename>/etc/profile.d/umask.sh</filename></title>
|
---|
| 233 |
|
---|
| 234 | <para>Setting the <command>umask</command> value is important for security. Here
|
---|
| 235 | we turn off the default group write permissions for system users and when the
|
---|
| 236 | user name and group name are not the same.</para>
|
---|
[b554263] | 237 |
|
---|
[1a396398] | 238 | <screen><userinput><command>cat > /etc/profile.d/umask.sh << "EOF"</command>
|
---|
| 239 | # By default we want the umask to get set.
|
---|
| 240 | if [ "$(id -gn)" = "$(id -un)" -a $EUID -gt 99 ] ; then
|
---|
| 241 | umask 002
|
---|
| 242 | else
|
---|
| 243 | umask 022
|
---|
| 244 | fi
|
---|
| 245 | <command>EOF</command></userinput></screen>
|
---|
| 246 | </sect3>
|
---|
| 247 |
|
---|
| 248 | <sect3>
|
---|
| 249 | <title><filename>/etc/profile.d/X.sh</filename></title>
|
---|
| 250 |
|
---|
| 251 | <para>If <application>X</application> is installed, we also update the <envar>PATH</envar>
|
---|
| 252 | and <envar>PKG_CONFIG_PATH</envar> variables.</para>
|
---|
| 253 |
|
---|
| 254 | <screen><userinput><command>cat > /etc/profile.d/X.sh << "EOF"</command>
|
---|
| 255 | if [ -x /usr/X11R6/bin/X ]; then
|
---|
| 256 | pathappend /usr/X11R6/bin
|
---|
| 257 | fi
|
---|
| 258 | if [ -d /usr/X11R6/lib/pkgconfig ] ; then
|
---|
| 259 | pathappend /usr/X11R6/lib/pkgconfig PKG_CONFIG_PATH
|
---|
| 260 | fi
|
---|
| 261 | <command>EOF</command></userinput></screen>
|
---|
| 262 | </sect3>
|
---|
| 263 |
|
---|
| 264 | <sect3>
|
---|
| 265 | <title><filename>/etc/profile.d/xterm-titlebars.sh</filename></title>
|
---|
| 266 |
|
---|
| 267 | <para>This script shows an example of a different way of setting the prompt. The normal
|
---|
| 268 | variable, <envar>PS1</envar>, is supplemented by <envar>PROMPT_COMMAND</envar>.
|
---|
| 269 | If set, the value of <envar>PROMPT_COMMAND</envar> is executed as a command prior to
|
---|
| 270 | issuing each primary prompt. </para>
|
---|
| 271 |
|
---|
| 272 | <screen><userinput><command>cat > /etc/profile.d/xterm-titlebars.sh << "EOF"</command>
|
---|
| 273 | # The substring match ensures this will work for "xterm" and "xterm-xfree86".
|
---|
| 274 | if [ "${TERM:0:5}" = "xterm" ]; then
|
---|
| 275 | PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME} : ${PWD}\007"'
|
---|
| 276 | export PROMPT_COMMAND
|
---|
| 277 | fi
|
---|
[766bbe40] | 278 | <command>EOF</command></userinput></screen>
|
---|
[0ca9f97] | 279 | </sect3>
|
---|
| 280 |
|
---|
| 281 | <sect3>
|
---|
| 282 | <title><filename>/etc/profile.d/i18n.sh</filename></title>
|
---|
| 283 |
|
---|
| 284 | <para>This script shows how to set some environment variables necessary for
|
---|
[d295e92] | 285 | native language support. Setting these variables properly gives you:</para>
|
---|
| 286 |
|
---|
| 287 | <itemizedlist spacing="compact">
|
---|
| 288 | <listitem><para>the output of programs translated into your native
|
---|
| 289 | language</para></listitem>
|
---|
| 290 | <listitem><para>correct classification of characters into letters, digits and
|
---|
| 291 | other classes – this is necessary for <application>Bash</application> to
|
---|
| 292 | accept keystrokes properly in non-English locales</para></listitem>
|
---|
| 293 | <listitem><para>the alphabetical sorting order correct for your
|
---|
| 294 | country</para></listitem>
|
---|
| 295 | <listitem><para>proper default paper size</para></listitem>
|
---|
| 296 | <listitem><para>correct formatting of monetary, time and date
|
---|
| 297 | values</para></listitem>
|
---|
| 298 | </itemizedlist>
|
---|
| 299 |
|
---|
| 300 | <para>Replace <replaceable>[ll]</replaceable> with the two-letter code for
|
---|
| 301 | your language (e.g., <quote>en</quote>) and
|
---|
| 302 | <replaceable>[CC]</replaceable> with the two-letter code for your country
|
---|
[0ca9f97] | 303 | (e.g., <quote>GB</quote>). Also you may need to specify (and this is actually
|
---|
| 304 | the preferred form) your character encoding (e.g., <quote>iso8859-1</quote>)
|
---|
| 305 | after a dot (so that the result is <quote>en_GB.iso8859-1</quote>). Issue the
|
---|
| 306 | following command for more information:</para>
|
---|
| 307 |
|
---|
| 308 | <screen><userinput><command>man 3 setlocale</command></userinput></screen>
|
---|
| 309 |
|
---|
| 310 | <para>The list of all locales supported by <application>Glibc</application>
|
---|
| 311 | can be obtained by running the following command:</para>
|
---|
| 312 |
|
---|
| 313 | <screen><userinput><command>locale -a</command></userinput></screen>
|
---|
| 314 |
|
---|
[d295e92] | 315 | <para>After you are sure about your locale settings, create the
|
---|
[0ca9f97] | 316 | <filename>/etc/profile.d/i18n.sh</filename> file:</para>
|
---|
| 317 |
|
---|
| 318 | <screen><userinput><command>cat > /etc/profile.d/i18n.sh << "EOF"</command>
|
---|
| 319 | # Set up i18n variables
|
---|
[d295e92] | 320 | export LC_ALL=<replaceable>[ll]</replaceable>_<replaceable>[CC]</replaceable>
|
---|
| 321 | export LANG=<replaceable>[ll]</replaceable>_<replaceable>[CC]</replaceable>
|
---|
[0ca9f97] | 322 | <command>EOF</command></userinput></screen>
|
---|
[b554263] | 323 |
|
---|
[d295e92] | 324 | <para>Note: Setting LC_ALL sets the same value for all locale categories. For
|
---|
| 325 | better control, you may prefer to set values individually for all categories
|
---|
| 326 | listed in the output of the <command>locale</command> command.</para>
|
---|
[11fcaea2] | 327 | </sect3>
|
---|
[d295e92] | 328 |
|
---|
| 329 | <sect3>
|
---|
| 330 | <title><filename>Other initialization values</filename></title>
|
---|
| 331 |
|
---|
[1a396398] | 332 | <para>Other initialization can easily be added to the <filename>profile</filename>
|
---|
| 333 | by adding additional scripts to the
|
---|
| 334 | <filename class='directory'>/etc/profile.d</filename> directory.</para>
|
---|
| 335 | </sect3>
|
---|
[0ca9f97] | 336 |
|
---|
[1a396398] | 337 | </sect2>
|
---|
| 338 |
|
---|
| 339 | <sect2>
|
---|
| 340 | <title><filename>/etc/bashrc</filename></title>
|
---|
[b554263] | 341 | <para>Here is a base <filename>/etc/bashrc</filename>. Comments in the
|
---|
| 342 | file should explain everything you need.</para>
|
---|
| 343 |
|
---|
[766bbe40] | 344 | <screen><userinput><command>cat > /etc/bashrc << "EOF"</command>
|
---|
| 345 | # Begin /etc/bashrc
|
---|
[b554263] | 346 | # Written for Beyond Linux From Scratch
|
---|
| 347 | # by James Robertson <jameswrobertson@earthlink.net>
|
---|
| 348 |
|
---|
| 349 | # System wide aliases and functions.
|
---|
| 350 |
|
---|
| 351 | # System wide environment variables and startup programs should go into
|
---|
| 352 | # /etc/profile. Personal environment variables and startup programs
|
---|
| 353 | # should go into ~/.bash_profile. Personal aliases and functions should
|
---|
| 354 | # go into ~/.bashrc
|
---|
| 355 |
|
---|
| 356 | # Provides a colored /bin/ls command. Used in conjunction with code in
|
---|
| 357 | # /etc/profile.
|
---|
[1a396398] | 358 |
|
---|
[b554263] | 359 | alias ls='ls --color=auto'
|
---|
| 360 |
|
---|
[1a396398] | 361 | # Provides prompt for non-login shells, specifically shells started
|
---|
| 362 | # in the <application>X</application> environment. [Review the LFS archive thread titled
|
---|
| 363 | # PS1 Environment Variable for a great case study behind this script addendum.]
|
---|
| 364 |
|
---|
[3383489] | 365 | #export PS1="[\u@\h \w]\\$ "
|
---|
| 366 | export PS1='\u@\h:\w\$ '
|
---|
[28a9992] | 367 |
|
---|
[766bbe40] | 368 | # End /etc/bashrc
|
---|
| 369 | <command>EOF</command></userinput></screen>
|
---|
[1a396398] | 370 | </sect2>
|
---|
| 371 |
|
---|
| 372 |
|
---|
| 373 | <sect2>
|
---|
| 374 | <title><filename>~/.bash_profile</filename></title>
|
---|
[b554263] | 375 |
|
---|
[1a396398] | 376 | <para>Here is a base <filename>~/.bash_profile</filename>. If you want each
|
---|
| 377 | new user to have this file automatically, just change the output of
|
---|
| 378 | the command to <filename>/etc/skel/.bash_profile</filename> and check the
|
---|
[cfc2a54] | 379 | permissions after the command is run. You can then copy
|
---|
[1a396398] | 380 | <filename>/etc/skel/.bash_profile</filename> to the home directories of already
|
---|
| 381 | existing users, including root, and set the owner and group appropriately.
|
---|
[cfc2a54] | 382 | </para>
|
---|
[b554263] | 383 |
|
---|
[766bbe40] | 384 | <screen><userinput><command>cat > ~/.bash_profile << "EOF"</command>
|
---|
| 385 | # Begin ~/.bash_profile
|
---|
[b554263] | 386 | # Written for Beyond Linux From Scratch
|
---|
| 387 | # by James Robertson <jameswrobertson@earthlink.net>
|
---|
[1a396398] | 388 | # updated by Bruce Dubbs <bdubbs@linuxfromscratch.org>
|
---|
[b554263] | 389 |
|
---|
[64d97b7c] | 390 | # Personal environment variables and startup programs.
|
---|
[b554263] | 391 |
|
---|
| 392 | # Personal aliases and functions should go in ~/.bashrc. System wide
|
---|
| 393 | # environment variables and startup programs are in /etc/profile.
|
---|
| 394 | # System wide aliases and functions are in /etc/bashrc.
|
---|
| 395 |
|
---|
[1a396398] | 396 | append () {
|
---|
| 397 | # First remove the directory
|
---|
| 398 | local IFS=':'
|
---|
| 399 | local NEWPATH
|
---|
| 400 | for DIR in $PATH; do
|
---|
| 401 | if [ "$DIR" != "$1" ]; then
|
---|
[3f1b51a] | 402 | NEWPATH=${NEWPATH:+$NEWPATH:}$DIR
|
---|
[1a396398] | 403 | fi
|
---|
| 404 | done
|
---|
| 405 |
|
---|
| 406 | # Then append the directory
|
---|
| 407 | export PATH=$NEWPATH:$1
|
---|
| 408 | }
|
---|
| 409 |
|
---|
[b554263] | 410 | if [ -f "$HOME/.bashrc" ] ; then
|
---|
[7008de1] | 411 | source $HOME/.bashrc
|
---|
[b554263] | 412 | fi
|
---|
| 413 |
|
---|
| 414 | if [ -d "$HOME/bin" ] ; then
|
---|
[1a396398] | 415 | append $HOME/bin
|
---|
[b554263] | 416 | fi
|
---|
| 417 |
|
---|
[1a396398] | 418 | unset append
|
---|
[b554263] | 419 |
|
---|
[766bbe40] | 420 | # End ~/.bash_profile
|
---|
| 421 | <command>EOF</command></userinput></screen>
|
---|
[1a396398] | 422 | </sect2>
|
---|
| 423 |
|
---|
| 424 | <sect2>
|
---|
| 425 | <title><filename>~/.bashrc</filename></title>
|
---|
[b554263] | 426 |
|
---|
[1a396398] | 427 | <para>Here is a base <filename>~/.bashrc</filename>. The comments and
|
---|
[8604d92f] | 428 | instructions for using <filename class="directory">/etc/skel</filename> for
|
---|
[1a396398] | 429 | <filename>.bash_profile</filename> above also apply here. Only the target file
|
---|
| 430 | names are different.</para>
|
---|
[b554263] | 431 |
|
---|
[766bbe40] | 432 | <screen><userinput><command>cat > ~/.bashrc << "EOF"</command>
|
---|
| 433 | # Begin ~/.bashrc
|
---|
[b554263] | 434 | # Written for Beyond Linux From Scratch
|
---|
| 435 | # by James Robertson <jameswrobertson@earthlink.net>
|
---|
| 436 |
|
---|
| 437 | # Personal aliases and functions.
|
---|
| 438 |
|
---|
| 439 | # Personal environment variables and startup programs should go in
|
---|
[64d97b7c] | 440 | # ~/.bash_profile. System wide environment variables and startup
|
---|
[b554263] | 441 | # programs are in /etc/profile. System wide aliases and functions are
|
---|
| 442 | # in /etc/bashrc.
|
---|
| 443 |
|
---|
| 444 | if [ -f "/etc/bashrc" ] ; then
|
---|
[7008de1] | 445 | source /etc/bashrc
|
---|
[b554263] | 446 | fi
|
---|
| 447 |
|
---|
[766bbe40] | 448 | # End ~/.bashrc
|
---|
| 449 | <command>EOF</command></userinput></screen>
|
---|
[1a396398] | 450 | </sect2>
|
---|
| 451 |
|
---|
| 452 |
|
---|
| 453 | <sect2>
|
---|
| 454 | <title><filename>~/.bash_logout</filename></title>
|
---|
[b554263] | 455 |
|
---|
[1a396398] | 456 | <para>This is an empty <filename>~/.bash_logout</filename> that can be used as
|
---|
| 457 | a template. You will notice that the base <filename>~/.bash_logout</filename>
|
---|
| 458 | does not include a <userinput>clear</userinput> command. This is because the
|
---|
| 459 | clear is handled in the <filename>/etc/issue</filename> file.</para>
|
---|
[b554263] | 460 |
|
---|
[766bbe40] | 461 | <screen><userinput><command>cat > ~/.bash_logout << "EOF"</command>
|
---|
| 462 | # Begin ~/.bash_logout
|
---|
[b554263] | 463 | # Written for Beyond Linux From Scratch
|
---|
| 464 | # by James Robertson <jameswrobertson@earthlink.net>
|
---|
| 465 |
|
---|
| 466 | # Personal items to perform on logout.
|
---|
| 467 |
|
---|
[766bbe40] | 468 | # End ~/.bash_logout
|
---|
| 469 | <command>EOF</command></userinput></screen>
|
---|
[1a396398] | 470 | </sect2>
|
---|
| 471 |
|
---|
| 472 |
|
---|
| 473 | <sect2>
|
---|
| 474 | <title><filename>/etc/dircolors</filename></title>
|
---|
| 475 |
|
---|
[3b7081ba] | 476 | <para> If you want to use the <filename>dircolors</filename> capability, then
|
---|
[1a396398] | 477 | run the following command. The <filename class="directory">/etc/skel</filename>
|
---|
| 478 | setup steps seen above also can be used here to provide a
|
---|
| 479 | <filename>.dircolors</filename> file when a new user is set up. As before, just
|
---|
| 480 | change the output file name on the following command and assure the
|
---|
[692e12c] | 481 | permissions, owner, and group are correct on the files created and/or copied.
|
---|
[cfc2a54] | 482 | </para>
|
---|
| 483 |
|
---|
[1a396398] | 484 | <screen><userinput><command>dircolors -p > /etc/dircolors</command></userinput></screen>
|
---|
[b554263] | 485 |
|
---|
[1a396398] | 486 | <para>If you wish to customize the colors used for different file types, you can
|
---|
| 487 | edit the <filename>/etc/dircolors</filename> file. The instructions for setting
|
---|
| 488 | the colors are embedded in the file.</para>
|
---|
| 489 |
|
---|
| 490 |
|
---|
| 491 | <para>Finally, Ian Macdonald has written an excellent collection of tips and
|
---|
[7008de1] | 492 | tricks to enhance your shell environment. You can read it online at
|
---|
| 493 | <ulink
|
---|
[2a87a398] | 494 | url="http://www.caliban.org/bash/index.shtml">http://www.caliban.org/bash/index.shtml</ulink>.</para>
|
---|
[1a396398] | 495 | </sect2>
|
---|
[b554263] | 496 | </sect1>
|
---|