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