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