source: postlfs/config/profile.xml@ ad33bab6

10.0 10.1 11.0 11.1 11.2 11.3 12.0 12.1 6.0 6.1 6.2 6.2.0 6.2.0-rc1 6.2.0-rc2 6.3 6.3-rc1 6.3-rc2 6.3-rc3 7.10 7.4 7.5 7.6 7.6-blfs 7.6-systemd 7.7 7.8 7.9 8.0 8.1 8.2 8.3 8.4 9.0 9.1 basic bdubbs/svn elogind gnome kde5-13430 kde5-14269 kde5-14686 kea ken/TL2024 ken/inkscape-core-mods ken/tuningfonts krejzi/svn lazarus lxqt nosym perl-modules plabs/newcss plabs/python-mods python3.11 qt5new rahul/power-profiles-daemon renodr/vulkan-addition systemd-11177 systemd-13485 trunk upgradedb xry111/intltool xry111/llvm18 xry111/soup3 xry111/test-20220226 xry111/xf86-video-removal
Last change on this file since ad33bab6 was ad33bab6, checked in by Bruce Dubbs <bdubbs@…>, 19 years ago

Updates to /etc/bashrc

git-svn-id: svn://svn.linuxfromscratch.org/BLFS/trunk/BOOK@3076 af4574ff-66df-0310-9fd7-8a98e5e911e0

  • Property mode set to 100644
File size: 18.4 KB
RevLine 
[f8d632a]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]17referred to as just "the shell") uses a collection of startup files to
[1a396398]18help create an environment. Each file has a specific use and
[cfc2a54]19may affect login and interactive environments differently. The files in
[8604d92f]20the <filename class="directory">/etc</filename> directory generally provide global
[cfc2a54]21settings. If an equivalent file exists in your home directory it may
22override 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>
27file. This shell invocation normally reads <filename>/etc/profile</filename>
28and 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
33started with a terminal program such as <command>xterm</command> or
34<command>konsole</command> from within a graphical environment. This type of
35shell invocation normally copies the parent environment and then reads the
36user's <filename>~/.bashrc</filename> file for additional startup configuration
37instructions.</para>
38
39<para>A non-interactive shell is usually present when a shell script is
40running. It is non-interactive because it is processing a script and not
[3b7081ba]41waiting for user input between commands. For these shell invocations, only
42the environment inherited from the parent shell is used.</para>
[1a396398]43
44<para> The file <filename>~/.bash_logout</filename> is not used for an
45invocation of the shell. It is read and executed when a user exits from an
46interactive login shell.</para>
47
48<para>To the standard files, we also add <filename>/etc/bashrc</filename>
49which is called from the user's <filename>~/.bashrc</filename> for
50system 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
54Shells.</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
60setting up some helper functions and some basic parameters. It specifies some
61<filename>bash</filename> history parameters and, for security purposes,
62disables keeping a permanent history file for the root user. It also sets a
63default user prompt. It then calls small, single purpose scripts in the
64<filename class='directory'>/etc/profile.d</filename> directory to provide most
65initialization. </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]69bash</command> -- <emphasis role="strong">Node: Printing a
70Prompt.</emphasis></para>
[b554263]71
[766bbe40]72<screen><userinput><command>cat &gt; /etc/profile &lt;&lt; "EOF"</command>
73# Begin /etc/profile
[b554263]74# Written for Beyond Linux From Scratch
75# by James Robertson &lt;jameswrobertson@earthlink.net&gt;
[1a396398]76# modifications by Dagmar d'Surreal &lt;rivyqntzne@pbzpnfg.arg&gt;
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)
87pathremove () {
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
100pathprepend () {
101 pathremove $1 $2
102 local PATHVARIABLE=${2:-PATH}
103 export $PATHVARIABLE="$1${!PATHVARIABLE:+:${!PATHVARIABLE}}"
104}
105
106pathappend () {
107 pathremove $1 $2
108 local PATHVARIABLE=${2:-PATH}
109 export $PATHVARIABLE="${!PATHVARIABLE:+${!PATHVARIABLE}:}$1"
110}
111
[e9ef7b5e]112
113# Set the initial path
114export PATH=/bin:/usr/bin
115
[1a396398]116if [ $EUID -eq 0 ] ; then
[e9ef7b5e]117 pathappend /sbin:/usr/sbin
[1a396398]118 unset HISTFILE
[b554263]119fi
[1a396398]120
121# Setup some environment variables.
122export HISTSIZE=1000
123export HISTIGNORE="&amp;:[bf]g:exit"
124#export PS1="[\u@\h \w]\\$ "
125export PS1='\u@\h:\w\$ '
126
127for script in /etc/profile.d/*.sh ; do
[d3880c0]128 if [ -r $script ] ; then
[1a396398]129 . $script
130 fi
131done
132
133# Now to clean up after ourselves
134unset 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
148directory listing. They control colorized output of things like <command>ls
149--color</command>. The explaination of how to initialize these files is at the
150end of this section. </para>
[b554263]151
[1a396398]152
153<screen><userinput><command>cat &gt; /etc/profile.d/dircolors.sh &lt;&lt; "EOF"</command>
154# Setup for /bin/ls to support color, the alias is in /etc/bashrc.
155if [ -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]161fi
[1a396398]162alias 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
172the last section to put a dot at the end of your path. This will allow executables in the
[4faa9b91]173current working directory to be executed without specifiying a ./, however
[1a396398]174you are warned that this is generally considered a security hazard.</para>
175
176<screen><userinput><command>cat &gt; /etc/profile.d/extrapaths.sh &lt;&lt; "EOF"</command>
177if [ -d /usr/local/lib/pkgconfig ] ; then
178 pathappend /usr/local/lib/pkgconfig PKG_CONFIG_PATH
179fi
180if [ -d /usr/local/bin ]; then
181 pathprepend /usr/local/bin
[b554263]182fi
[1a396398]183if [ -d /usr/local/sbin -a $EUID -eq 0 ]; then
184 pathprepend /usr/local/sbin
185fi
[d3880c0]186for directory in $(find /opt/*/lib/pkgconfig -type d 2>/dev/null); do
[1a396398]187 pathappend $directory PKG_CONFIG_PATH
188done
[d3880c0]189for directory in $(find /opt/*/bin -type d 2>/dev/null); do
[1a396398]190 pathappend $directory
191done
192if [ -d ~/bin ]; then
193 pathprepend ~/bin
194fi
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.
205If the user does not have individual settings, it uses the global file.</para>
206
207<screen><userinput><command>cat &gt; /etc/profile.d/readline.sh &lt;&lt; "EOF"</command>
[b554263]208# Setup the INPUTRC environment variable.
209if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ] ; then
[1a396398]210 INPUTRC=/etc/inputrc
[b554263]211fi
[1a396398]212export 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 &gt; /etc/profile.d/tinker-term.sh &lt;&lt; "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
225if [ -n "$COLORTERM" ]; then
226 export TERM=xterm-color
227fi
228
229if [ "$TERM" = "xterm" ]; then
230 export TERM=xterm-color
[b554263]231fi
[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
239we turn off the default group write permissions for system users and when the
240user name and group name are not the same.</para>
[b554263]241
[1a396398]242<screen><userinput><command>cat &gt; /etc/profile.d/umask.sh &lt;&lt; "EOF"</command>
243# By default we want the umask to get set.
244if [ "$(id -gn)" = "$(id -un)" -a $EUID -gt 99 ] ; then
245 umask 002
246else
247 umask 022
248fi
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>
256and <envar>PKG_CONFIG_PATH</envar> variables.</para>
257
258<screen><userinput><command>cat &gt; /etc/profile.d/X.sh &lt;&lt; "EOF"</command>
259if [ -x /usr/X11R6/bin/X ]; then
260 pathappend /usr/X11R6/bin
261fi
262if [ -d /usr/X11R6/lib/pkgconfig ] ; then
263 pathappend /usr/X11R6/lib/pkgconfig PKG_CONFIG_PATH
264fi
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
272variable, <envar>PS1</envar>, is supplemented by <envar>PROMPT_COMMAND</envar>.
273If set, the value of <envar>PROMPT_COMMAND</envar> is executed as a command prior to
274issuing each primary prompt. </para>
275
276<screen><userinput><command>cat &gt; /etc/profile.d/xterm-titlebars.sh &lt;&lt; "EOF"</command>
277# The substring match ensures this will work for "xterm" and "xterm-xfree86".
278if [ "${TERM:0:5}" = "xterm" ]; then
279 PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME} : ${PWD}\007"'
280 export PROMPT_COMMAND
281fi
[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]289native 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
293language</para></listitem>
294<listitem><para>correct classification of characters into letters, digits and
295other classes &ndash; this is necessary for <application>Bash</application> to
296accept keystrokes properly in non-English locales</para></listitem>
297<listitem><para>the alphabetical sorting order correct for your
298country</para></listitem>
299<listitem><para>proper default paper size</para></listitem>
300<listitem><para>correct formatting of monetary, time and date
301values</para></listitem>
302</itemizedlist>
303
304<para>Replace <replaceable>[ll]</replaceable> with the two-letter code for
305your 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
308the preferred form) your character encoding (e.g., <quote>iso8859-1</quote>)
309after a dot (so that the result is <quote>en_GB.iso8859-1</quote>). Issue the
310following 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>
315can 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 &gt; /etc/profile.d/i18n.sh &lt;&lt; "EOF"</command>
323# Set up i18n variables
[d295e92]324export LC_ALL=<replaceable>[ll]</replaceable>_<replaceable>[CC]</replaceable>
325export LANG=<replaceable>[ll]</replaceable>_<replaceable>[CC]</replaceable>
[ad59f9e2]326export 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]330better control, you may prefer to set values individually for all categories
331listed in the output of the <command>locale</command> command.</para>
[ad59f9e2]332
333<para>The <envar>G_FILENAME_ENCODING</envar> variable tells applications
334such as <application>Glib</application> and
335<application><acronym>GTK</acronym>+</application> that filenames are in
336the default locale encoding and not in <acronym>UTF</acronym>-8 as
337assumed 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>
344by 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
353file should explain everything you need.</para>
354
[766bbe40]355<screen><userinput><command>cat &gt; /etc/bashrc &lt;&lt; "EOF"</command>
356# Begin /etc/bashrc
[b554263]357# Written for Beyond Linux From Scratch
358# by James Robertson &lt;jameswrobertson@earthlink.net&gt;
[ad33bab6]359# updated by Bruce Dubbs &lt;bdubbs@linuxfromscratch.org&gt;
360
361# Make sure that the terminal is set up properly for each shell
362
363if [ -f /etc/profile.d/tinker-term.sh ]; then
364 source /etc/profile.d/tinker-term.sh
365fi
366
367if [ -f /etc/profile.d/xterm-titlebars.sh ]; then
368 source /etc/profile.d/xterm-titlebars.sh
369fi
[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]381alias 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]\\$ "
388export 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
399new user to have this file automatically, just change the output of
400the command to <filename>/etc/skel/.bash_profile</filename> and check the
[cfc2a54]401permissions after the command is run. You can then copy
[1a396398]402<filename>/etc/skel/.bash_profile</filename> to the home directories of already
403existing users, including root, and set the owner and group appropriately.
[cfc2a54]404</para>
[b554263]405
[766bbe40]406<screen><userinput><command>cat &gt; ~/.bash_profile &lt;&lt; "EOF"</command>
407# Begin ~/.bash_profile
[b554263]408# Written for Beyond Linux From Scratch
409# by James Robertson &lt;jameswrobertson@earthlink.net&gt;
[1a396398]410# updated by Bruce Dubbs &lt;bdubbs@linuxfromscratch.org&gt;
[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]418append () {
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]432if [ -f "$HOME/.bashrc" ] ; then
[7008de1]433 source $HOME/.bashrc
[b554263]434fi
435
436if [ -d "$HOME/bin" ] ; then
[1a396398]437 append $HOME/bin
[b554263]438fi
439
[1a396398]440unset 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]450instructions for using <filename class="directory">/etc/skel</filename> for
[1a396398]451<filename>.bash_profile</filename> above also apply here. Only the target file
452names are different.</para>
[b554263]453
[766bbe40]454<screen><userinput><command>cat &gt; ~/.bashrc &lt;&lt; "EOF"</command>
455# Begin ~/.bashrc
[b554263]456# Written for Beyond Linux From Scratch
457# by James Robertson &lt;jameswrobertson@earthlink.net&gt;
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
466if [ -f "/etc/bashrc" ] ; then
[7008de1]467 source /etc/bashrc
[b554263]468fi
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
479a template. You will notice that the base <filename>~/.bash_logout</filename>
480does not include a <userinput>clear</userinput> command. This is because the
481clear is handled in the <filename>/etc/issue</filename> file.</para>
[b554263]482
[766bbe40]483<screen><userinput><command>cat &gt; ~/.bash_logout &lt;&lt; "EOF"</command>
484# Begin ~/.bash_logout
[b554263]485# Written for Beyond Linux From Scratch
486# by James Robertson &lt;jameswrobertson@earthlink.net&gt;
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]499run the following command. The <filename class="directory">/etc/skel</filename>
500setup 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
502change the output file name on the following command and assure the
[692e12c]503permissions, 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
509edit the <filename>/etc/dircolors</filename> file. The instructions for setting
510the colors are embedded in the file.</para>
511
512
513<para>Finally, Ian Macdonald has written an excellent collection of tips and
[7008de1]514tricks to enhance your shell environment. You can read it online at
515<ulink
[2a87a398]516url="http://www.caliban.org/bash/index.shtml">http://www.caliban.org/bash/index.shtml</ulink>.</para>
[1a396398]517</sect2>
[b554263]518</sect1>
Note: See TracBrowser for help on using the repository browser.