Ticket #236: profile.patch

File profile.patch, 6.5 KB (added by jwrober@…, 21 years ago)

v1.1.1.2 of file. First attempt for the book.

  • profile.xml

     
    11<sect1 id="postlfs-config-profile">
    22<?dbhtml filename="profile.html" dir="postlfs"?>
    3 <title>/etc/profile and ~/.bash_*</title>
     3<title>The Bash Shell Startup Files</title>
    44
    5 <para>NEW PAGE TO BE WRITTEN</para>
     5<para>The shell program <filename>/bin/bash</filename> (hereafter
     6refered to as just "the shell") uses a collection of startup files to
     7help create an environment to run in.  Each file has a specific use and
     8non-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
     12interactive non-login shell is started at the command line (e.g.
     13[prompt]$<userinput>/bin/bash</userinput>).  A non-interactive shell is
     14usually present when a shell script is running.  It is non-interactive
     15because it is processing a script and not waiting for user input between
     16commands.</para>
     17
     18<para>For more information see <filename>info bash</filename> -- Nodes:
     19Bash Startup Files and Interactive Shells</para>
     20
     21<para>The following files are needed to make sure that the correct
     22environment 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
     27shell.  It is read by the shell when a user logouts of the system.  The
     28files <filename>/etc/profile</filename> and
     29<filename>~/.bash_profile</filename> are read when the shell is invoked
     30as a interactive login shell.  The file <filename>~/.bashrc</filename>
     31is read when the shell is invoked as an interactive non-login
     32shell.</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
     49pathman () {
     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.
     60if [ $(id -u) = 0 ] ; then
     61        if [ -d "/usr/local/sbin" ] ; then
     62                pathman /usr/local/sbin last
     63        fi
     64fi
     65
     66if [ $(id -u) != 0 ] ; then
     67        if [ -d "/usr/local/bin" ] ; then
     68                pathman /usr/local/bin last
     69        fi
     70fi
     71
     72if [ -d "/usr/X11R6/bin" ] ; then
     73        pathman /usr/X11R6/bin last
     74fi
     75
     76# Setup some environment variables.
     77USER=$(id -un)
     78LOGNAME=$USER
     79MAIL="/var/mail/$USER"
     80HOSTNAME=$(/bin/hostname)
     81HISTSIZE=1000
     82PS1="[\u@\h \w]\\$ "
     83
     84# Setup the INPUTRC environment variable.
     85if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ] ; then
     86        INPUTRC=/etc/inputrc
     87fi
     88
     89# Setup for /bin/ls to support color, the alias is in /etc/bashrc.
     90if [ -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
     96fi
     97
     98export 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
     105file 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.
     121if [ "$(id -gn)" = "$(id -un)" -a $(id -u) -gt 99 ] ; then
     122        umask 002
     123else
     124        umask 022
     125fi
     126
     127# Provides a colored /bin/ls command.  Used in conjunction with code in
     128# /etc/profile.
     129alias 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
     135the 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
     148if [ -f "$HOME/.bashrc" ] ; then
     149        . $HOME/.bashrc
     150fi
     151
     152if [ -d "$HOME/bin" ] ; then
     153        pathman $HOME/bin last
     154fi
     155
     156export PATH
     157
     158# End ~/.bash_profile
     159</screen></para>
     160
     161<para>Here is a base <filename>~/.bashrc</filename>.  Comments in the
     162file 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
     176if [ -f "/etc/bashrc" ] ; then
     177        . /etc/bashrc
     178fi
     179
     180# End ~/.bashrc
     181</screen></para>
     182
     183<para>Here is a base <filename>~/.bash_logout</filename>.  Comments in
     184the 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.
     201The file in the <filename>/etc</filename> directory should be used for
     202global settings and if one exists in your home directory then it will
     203overwrite 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>
    6206
    7207</sect1>
    8208