source: postlfs/config/profile.xml@ 0ca9f97

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 0ca9f97 was 0ca9f97, checked in by Randy McMurchy <randy@…>, 20 years ago

Added i18n section to Bash Shell Startup Files

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

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