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