source: postlfs/config/profile.xml@ ad33bab

10.0 10.1 11.0 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 ken/refactor-virt krejzi/svn lazarus nosym perl-modules qt5new systemd-11177 systemd-13485 trunk xry111/git-date xry111/git-date-for-trunk xry111/git-date-test
Last change on this file since ad33bab was ad33bab, checked in by Bruce Dubbs <bdubbs@…>, 17 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
Line 
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
8<sect1 id="postlfs-config-profile" xreflabel="The Bash Shell Startup Files">
9<sect1info>
10<othername>$LastChangedBy$</othername>
11<date>$Date$</date>
12</sect1info>
13<?dbhtml filename="profile.html"?>
14<title>The Bash Shell Startup Files</title>
15
16<para>The shell program <filename>/bin/bash</filename> (hereafter
17referred to as just "the shell") uses a collection of startup files to
18help create an environment. Each file has a specific use and
19may affect login and interactive environments differently. The files in
20the <filename class="directory">/etc</filename> directory generally provide global
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
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
31(e.g., <prompt>[prompt]$</prompt><command>/bin/bash</command>) or by the
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
41waiting for user input between commands. For these shell invocations, only
42the environment inherited from the parent shell is used.</para>
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>
51
52<para>For more information see <command>info bash</command> --
53<emphasis role="strong">Nodes: Bash Startup Files and Interactive
54Shells.</emphasis></para>
55
56<sect2>
57<title><filename>/etc/profile</filename></title>
58
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>
66
67<para>For more information on the escape sequences you can use for your prompt
68(e.g., the <envar>PS1</envar> environment variable) see <command>info
69bash</command> -- <emphasis role="strong">Node: Printing a
70Prompt.</emphasis></para>
71
72<screen><userinput><command>cat &gt; /etc/profile &lt;&lt; "EOF"</command>
73# Begin /etc/profile
74# Written for Beyond Linux From Scratch
75# by James Robertson &lt;jameswrobertson@earthlink.net&gt;
76# modifications by Dagmar d'Surreal &lt;rivyqntzne@pbzpnfg.arg&gt;
77
78# System wide environment variables and startup programs.
79
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.
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"
98}
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
112
113# Set the initial path
114export PATH=/bin:/usr/bin
115
116if [ $EUID -eq 0 ] ; then
117 pathappend /sbin:/usr/sbin
118 unset HISTFILE
119fi
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
128 if [ -r $script ] ; then
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>
151
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
161fi
162alias ls='ls --color=auto'
163<command>EOF</command></userinput></screen>
164</sect3>
165
166
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
173current working directory to be executed without specifiying a ./, however
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
182fi
183if [ -d /usr/local/sbin -a $EUID -eq 0 ]; then
184 pathprepend /usr/local/sbin
185fi
186for directory in $(find /opt/*/lib/pkgconfig -type d 2>/dev/null); do
187 pathappend $directory PKG_CONFIG_PATH
188done
189for directory in $(find /opt/*/bin -type d 2>/dev/null); do
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>
200
201<sect3>
202<title><filename>/etc/profile.d/readline.sh</filename></title>
203
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>
208# Setup the INPUTRC environment variable.
209if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ] ; then
210 INPUTRC=/etc/inputrc
211fi
212export INPUTRC
213<command>EOF</command></userinput></screen>
214</sect3>
215
216<sect3>
217<title><filename>/etc/profile.d/tinker-term.sh</filename></title>
218
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
231fi
232<command>EOF</command></userinput></screen>
233</sect3>
234
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>
241
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
282<command>EOF</command></userinput></screen>
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
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
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
319<para>After you are sure about your locale settings, create the
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
324export LC_ALL=<replaceable>[ll]</replaceable>_<replaceable>[CC]</replaceable>
325export LANG=<replaceable>[ll]</replaceable>_<replaceable>[CC]</replaceable>
326export G_FILENAME_ENCODING=@locale
327<command>EOF</command></userinput></screen>
328
329<para>The <envar>LC_ALL</envar> variable sets the same value for all locale categories. For
330better control, you may prefer to set values individually for all categories
331listed in the output of the <command>locale</command> command.</para>
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>
338</sect3>
339
340<sect3>
341<title><filename>Other initialization values</filename></title>
342
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>
347
348</sect2>
349
350<sect2>
351<title><filename>/etc/bashrc</filename></title>
352<para>Here is a base <filename>/etc/bashrc</filename>. Comments in the
353file should explain everything you need.</para>
354
355<screen><userinput><command>cat &gt; /etc/bashrc &lt;&lt; "EOF"</command>
356# Begin /etc/bashrc
357# Written for Beyond Linux From Scratch
358# by James Robertson &lt;jameswrobertson@earthlink.net&gt;
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
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.
380
381alias ls='ls --color=auto'
382
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
387#export PS1="[\u@\h \w]\\$ "
388export PS1='\u@\h:\w\$ '
389
390# End /etc/bashrc
391<command>EOF</command></userinput></screen>
392</sect2>
393
394
395<sect2>
396<title><filename>~/.bash_profile</filename></title>
397
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
401permissions after the command is run. You can then copy
402<filename>/etc/skel/.bash_profile</filename> to the home directories of already
403existing users, including root, and set the owner and group appropriately.
404</para>
405
406<screen><userinput><command>cat &gt; ~/.bash_profile &lt;&lt; "EOF"</command>
407# Begin ~/.bash_profile
408# Written for Beyond Linux From Scratch
409# by James Robertson &lt;jameswrobertson@earthlink.net&gt;
410# updated by Bruce Dubbs &lt;bdubbs@linuxfromscratch.org&gt;
411
412# Personal environment variables and startup programs.
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
418append () {
419 # First remove the directory
420 local IFS=':'
421 local NEWPATH
422 for DIR in $PATH; do
423 if [ "$DIR" != "$1" ]; then
424 NEWPATH=${NEWPATH:+$NEWPATH:}$DIR
425 fi
426 done
427
428 # Then append the directory
429 export PATH=$NEWPATH:$1
430}
431
432if [ -f "$HOME/.bashrc" ] ; then
433 source $HOME/.bashrc
434fi
435
436if [ -d "$HOME/bin" ] ; then
437 append $HOME/bin
438fi
439
440unset append
441
442# End ~/.bash_profile
443<command>EOF</command></userinput></screen>
444</sect2>
445
446<sect2>
447<title><filename>~/.bashrc</filename></title>
448
449<para>Here is a base <filename>~/.bashrc</filename>. The comments and
450instructions for using <filename class="directory">/etc/skel</filename> for
451<filename>.bash_profile</filename> above also apply here. Only the target file
452names are different.</para>
453
454<screen><userinput><command>cat &gt; ~/.bashrc &lt;&lt; "EOF"</command>
455# Begin ~/.bashrc
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
462# ~/.bash_profile. System wide environment variables and startup
463# programs are in /etc/profile. System wide aliases and functions are
464# in /etc/bashrc.
465
466if [ -f "/etc/bashrc" ] ; then
467 source /etc/bashrc
468fi
469
470# End ~/.bashrc
471<command>EOF</command></userinput></screen>
472</sect2>
473
474
475<sect2>
476<title><filename>~/.bash_logout</filename></title>
477
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>
482
483<screen><userinput><command>cat &gt; ~/.bash_logout &lt;&lt; "EOF"</command>
484# Begin ~/.bash_logout
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
490# End ~/.bash_logout
491<command>EOF</command></userinput></screen>
492</sect2>
493
494
495<sect2>
496<title><filename>/etc/dircolors</filename></title>
497
498<para> If you want to use the <filename>dircolors</filename> capability, then
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
503permissions, owner, and group are correct on the files created and/or copied.
504</para>
505
506<screen><userinput><command>dircolors -p > /etc/dircolors</command></userinput></screen>
507
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
514tricks to enhance your shell environment. You can read it online at
515<ulink
516url="http://www.caliban.org/bash/index.shtml">http://www.caliban.org/bash/index.shtml</ulink>.</para>
517</sect2>
518</sect1>
Note: See TracBrowser for help on using the repository browser.