source: postlfs/config/profile.xml@ 5cd0959d

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 5cd0959d was 5cd0959d, checked in by Archaic <archaic@…>, 20 years ago

Resetting keywords

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

  • Property mode set to 100644
File size: 17.8 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>
326<command>EOF</command></userinput></screen>
327
328<para>Note: Setting LC_ALL sets the same value for all locale categories. For
329better control, you may prefer to set values individually for all categories
330listed in the output of the <command>locale</command> command.</para>
331</sect3>
332
333<sect3>
334<title><filename>Other initialization values</filename></title>
335
336<para>Other initialization can easily be added to the <filename>profile</filename>
337by adding additional scripts to the
338<filename class='directory'>/etc/profile.d</filename> directory.</para>
339</sect3>
340
341</sect2>
342
343<sect2>
344<title><filename>/etc/bashrc</filename></title>
345<para>Here is a base <filename>/etc/bashrc</filename>. Comments in the
346file should explain everything you need.</para>
347
348<screen><userinput><command>cat &gt; /etc/bashrc &lt;&lt; "EOF"</command>
349# Begin /etc/bashrc
350# Written for Beyond Linux From Scratch
351# by James Robertson &lt;jameswrobertson@earthlink.net&gt;
352
353# System wide aliases and functions.
354
355# System wide environment variables and startup programs should go into
356# /etc/profile. Personal environment variables and startup programs
357# should go into ~/.bash_profile. Personal aliases and functions should
358# go into ~/.bashrc
359
360# Provides a colored /bin/ls command. Used in conjunction with code in
361# /etc/profile.
362
363alias ls='ls --color=auto'
364
365# Provides prompt for non-login shells, specifically shells started
366# in the <application>X</application> environment. [Review the LFS archive thread titled
367# PS1 Environment Variable for a great case study behind this script addendum.]
368
369#export PS1="[\u@\h \w]\\$ "
370export PS1='\u@\h:\w\$ '
371
372# End /etc/bashrc
373<command>EOF</command></userinput></screen>
374</sect2>
375
376
377<sect2>
378<title><filename>~/.bash_profile</filename></title>
379
380<para>Here is a base <filename>~/.bash_profile</filename>. If you want each
381new user to have this file automatically, just change the output of
382the command to <filename>/etc/skel/.bash_profile</filename> and check the
383permissions after the command is run. You can then copy
384<filename>/etc/skel/.bash_profile</filename> to the home directories of already
385existing users, including root, and set the owner and group appropriately.
386</para>
387
388<screen><userinput><command>cat &gt; ~/.bash_profile &lt;&lt; "EOF"</command>
389# Begin ~/.bash_profile
390# Written for Beyond Linux From Scratch
391# by James Robertson &lt;jameswrobertson@earthlink.net&gt;
392# updated by Bruce Dubbs &lt;bdubbs@linuxfromscratch.org&gt;
393
394# Personal environment variables and startup programs.
395
396# Personal aliases and functions should go in ~/.bashrc. System wide
397# environment variables and startup programs are in /etc/profile.
398# System wide aliases and functions are in /etc/bashrc.
399
400append () {
401 # First remove the directory
402 local IFS=':'
403 local NEWPATH
404 for DIR in $PATH; do
405 if [ "$DIR" != "$1" ]; then
406 NEWPATH=${NEWPATH:+$NEWPATH:}$DIR
407 fi
408 done
409
410 # Then append the directory
411 export PATH=$NEWPATH:$1
412}
413
414if [ -f "$HOME/.bashrc" ] ; then
415 source $HOME/.bashrc
416fi
417
418if [ -d "$HOME/bin" ] ; then
419 append $HOME/bin
420fi
421
422unset append
423
424# End ~/.bash_profile
425<command>EOF</command></userinput></screen>
426</sect2>
427
428<sect2>
429<title><filename>~/.bashrc</filename></title>
430
431<para>Here is a base <filename>~/.bashrc</filename>. The comments and
432instructions for using <filename class="directory">/etc/skel</filename> for
433<filename>.bash_profile</filename> above also apply here. Only the target file
434names are different.</para>
435
436<screen><userinput><command>cat &gt; ~/.bashrc &lt;&lt; "EOF"</command>
437# Begin ~/.bashrc
438# Written for Beyond Linux From Scratch
439# by James Robertson &lt;jameswrobertson@earthlink.net&gt;
440
441# Personal aliases and functions.
442
443# Personal environment variables and startup programs should go in
444# ~/.bash_profile. System wide environment variables and startup
445# programs are in /etc/profile. System wide aliases and functions are
446# in /etc/bashrc.
447
448if [ -f "/etc/bashrc" ] ; then
449 source /etc/bashrc
450fi
451
452# End ~/.bashrc
453<command>EOF</command></userinput></screen>
454</sect2>
455
456
457<sect2>
458<title><filename>~/.bash_logout</filename></title>
459
460<para>This is an empty <filename>~/.bash_logout</filename> that can be used as
461a template. You will notice that the base <filename>~/.bash_logout</filename>
462does not include a <userinput>clear</userinput> command. This is because the
463clear is handled in the <filename>/etc/issue</filename> file.</para>
464
465<screen><userinput><command>cat &gt; ~/.bash_logout &lt;&lt; "EOF"</command>
466# Begin ~/.bash_logout
467# Written for Beyond Linux From Scratch
468# by James Robertson &lt;jameswrobertson@earthlink.net&gt;
469
470# Personal items to perform on logout.
471
472# End ~/.bash_logout
473<command>EOF</command></userinput></screen>
474</sect2>
475
476
477<sect2>
478<title><filename>/etc/dircolors</filename></title>
479
480<para> If you want to use the <filename>dircolors</filename> capability, then
481run the following command. The <filename class="directory">/etc/skel</filename>
482setup steps seen above also can be used here to provide a
483<filename>.dircolors</filename> file when a new user is set up. As before, just
484change the output file name on the following command and assure the
485permissions, owner, and group are correct on the files created and/or copied.
486</para>
487
488<screen><userinput><command>dircolors -p > /etc/dircolors</command></userinput></screen>
489
490<para>If you wish to customize the colors used for different file types, you can
491edit the <filename>/etc/dircolors</filename> file. The instructions for setting
492the colors are embedded in the file.</para>
493
494
495<para>Finally, Ian Macdonald has written an excellent collection of tips and
496tricks to enhance your shell environment. You can read it online at
497<ulink
498url="http://www.caliban.org/bash/index.shtml">http://www.caliban.org/bash/index.shtml</ulink>.</para>
499</sect2>
500</sect1>
Note: See TracBrowser for help on using the repository browser.