1 | <?xml version="1.0" encoding="ISO-8859-1"?>
|
---|
2 | <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
|
---|
3 | "http://www.oasis-open.org/docbook/xml/4.5/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 | <date>$Date$</date>
|
---|
13 | </sect1info>
|
---|
14 |
|
---|
15 | <title>The Bash Shell Startup Files</title>
|
---|
16 |
|
---|
17 | <para>
|
---|
18 | The shell program <filename>/bin/bash</filename> (hereafter referred to
|
---|
19 | as just "the shell") uses a collection of startup files to help create
|
---|
20 | an environment. Each file has a specific use and may affect login and
|
---|
21 | interactive environments differently. The files in the <filename
|
---|
22 | class="directory">/etc</filename> directory generally provide global
|
---|
23 | settings. If an equivalent file exists in your home directory it may
|
---|
24 | override the global settings.
|
---|
25 | </para>
|
---|
26 |
|
---|
27 | <para>
|
---|
28 | An interactive login shell is started after a successful login, using
|
---|
29 | <filename>/bin/login</filename>, by reading the
|
---|
30 | <filename>/etc/passwd</filename> file. This shell invocation normally reads
|
---|
31 | <filename>/etc/profile</filename> and its private equivalent
|
---|
32 | <filename>~/.bash_profile</filename> (or <filename>~/.profile</filename>
|
---|
33 | if called as <command>/bin/sh</command>) upon startup.
|
---|
34 | </para>
|
---|
35 |
|
---|
36 | <para>
|
---|
37 | An interactive non-login shell is normally started at the command-line
|
---|
38 | using a shell program (e.g.,
|
---|
39 | <prompt>[prompt]$</prompt><command>/bin/bash</command>) or by the
|
---|
40 | <command>/bin/su</command> command. An interactive non-login shell is also
|
---|
41 | started with a terminal program such as <command>xterm</command> or
|
---|
42 | <command>konsole</command> from within a graphical environment. This type
|
---|
43 | of shell invocation normally copies the parent environment and then reads
|
---|
44 | the user's <filename>~/.bashrc</filename> file for additional startup
|
---|
45 | configuration instructions.
|
---|
46 | </para>
|
---|
47 |
|
---|
48 | <para>
|
---|
49 | A non-interactive shell is usually present when a shell script is
|
---|
50 | running. It is non-interactive because it is processing a script and not
|
---|
51 | waiting for user input between commands. For these shell invocations, only
|
---|
52 | the environment inherited from the parent shell is used.
|
---|
53 | </para>
|
---|
54 |
|
---|
55 | <para>
|
---|
56 | The file <filename>~/.bash_logout</filename> is not used for an
|
---|
57 | invocation of the shell. It is read and executed when a user exits from an
|
---|
58 | interactive login shell.
|
---|
59 | </para>
|
---|
60 |
|
---|
61 | <para>
|
---|
62 | Many distributions use <filename>/etc/bashrc</filename> for system wide
|
---|
63 | initialization of non-login shells. This file is usually called from the
|
---|
64 | user's <filename>~/.bashrc</filename> file and is not built directly into
|
---|
65 | <command>bash</command> itself. This convention is followed in this
|
---|
66 | section.
|
---|
67 | </para>
|
---|
68 |
|
---|
69 | <para>
|
---|
70 | For more information see <command>info bash</command> --
|
---|
71 | <emphasis role="strong">Nodes: Bash Startup Files and Interactive
|
---|
72 | Shells</emphasis>.
|
---|
73 | </para>
|
---|
74 |
|
---|
75 | <note>
|
---|
76 | <para>
|
---|
77 | Most of the instructions below are used to create files located in the
|
---|
78 | <filename class='directory'>/etc</filename> directory structure which
|
---|
79 | requires you to execute the commands as the <systemitem
|
---|
80 | class='username'>root</systemitem> user. If you elect to create the
|
---|
81 | files in user's home directories instead, you should run the commands
|
---|
82 | as an unprivileged user.
|
---|
83 | </para>
|
---|
84 | </note>
|
---|
85 |
|
---|
86 | <para condition="html" role="usernotes">User Notes:
|
---|
87 | <ulink url="&blfs-wiki;/bash-shell-startup-files"/></para>
|
---|
88 |
|
---|
89 | <sect2 id="etc-profile-profile">
|
---|
90 | <title>/etc/profile</title>
|
---|
91 |
|
---|
92 | <indexterm zone="postlfs-config-profile etc-profile-profile">
|
---|
93 | <primary sortas="e-etc-profile">/etc/profile</primary>
|
---|
94 | </indexterm>
|
---|
95 |
|
---|
96 | <para>
|
---|
97 | Here is a base <filename>/etc/profile</filename>. This file starts by
|
---|
98 | setting up some helper functions and some basic parameters. It specifies
|
---|
99 | some <command>bash</command> history parameters and, for security
|
---|
100 | purposes, disables keeping a permanent history file for the <systemitem
|
---|
101 | class="username">root</systemitem> user. It also sets a default user
|
---|
102 | prompt. It then calls small, single purpose scripts in the <filename
|
---|
103 | class='directory'>/etc/profile.d</filename> directory to provide most
|
---|
104 | of the initialization.
|
---|
105 | </para>
|
---|
106 |
|
---|
107 | <para>
|
---|
108 | For more information on the escape sequences you can use for your prompt
|
---|
109 | (i.e., the <envar>PS1</envar> environment variable) see <command>info
|
---|
110 | bash</command> -- <emphasis role="strong">Node: Printing a
|
---|
111 | Prompt</emphasis>.
|
---|
112 | </para>
|
---|
113 |
|
---|
114 | <screen role="root"><?dbfo keep-together="auto"?><userinput>cat > /etc/profile << "EOF"
|
---|
115 | <literal># Begin /etc/profile
|
---|
116 | # Written for Beyond Linux From Scratch
|
---|
117 | # by James Robertson <jameswrobertson@earthlink.net>
|
---|
118 | # modifications by Dagmar d'Surreal <rivyqntzne@pbzpnfg.arg>
|
---|
119 |
|
---|
120 | # System wide environment variables and startup programs.
|
---|
121 |
|
---|
122 | # System wide aliases and functions should go in /etc/bashrc. Personal
|
---|
123 | # environment variables and startup programs should go into
|
---|
124 | # ~/.bash_profile. Personal aliases and functions should go into
|
---|
125 | # ~/.bashrc.
|
---|
126 |
|
---|
127 | # Functions to help us manage paths. Second argument is the name of the
|
---|
128 | # path variable to be modified (default: PATH)
|
---|
129 | pathremove () {
|
---|
130 | local IFS=':'
|
---|
131 | local NEWPATH
|
---|
132 | local DIR
|
---|
133 | local PATHVARIABLE=${2:-PATH}
|
---|
134 | for DIR in ${!PATHVARIABLE} ; do
|
---|
135 | if [ "$DIR" != "$1" ] ; then
|
---|
136 | NEWPATH=${NEWPATH:+$NEWPATH:}$DIR
|
---|
137 | fi
|
---|
138 | done
|
---|
139 | export $PATHVARIABLE="$NEWPATH"
|
---|
140 | }
|
---|
141 |
|
---|
142 | pathprepend () {
|
---|
143 | pathremove $1 $2
|
---|
144 | local PATHVARIABLE=${2:-PATH}
|
---|
145 | export $PATHVARIABLE="$1${!PATHVARIABLE:+:${!PATHVARIABLE}}"
|
---|
146 | }
|
---|
147 |
|
---|
148 | pathappend () {
|
---|
149 | pathremove $1 $2
|
---|
150 | local PATHVARIABLE=${2:-PATH}
|
---|
151 | export $PATHVARIABLE="${!PATHVARIABLE:+${!PATHVARIABLE}:}$1"
|
---|
152 | }
|
---|
153 |
|
---|
154 | export -f pathremove pathprepend pathappend
|
---|
155 |
|
---|
156 | # Set the initial path
|
---|
157 | export PATH=/usr/bin
|
---|
158 |
|
---|
159 | # Attempt to provide backward compatibility with LFS earlier than 11
|
---|
160 | if [ ! -L /bin ]; then
|
---|
161 | pathappend /bin
|
---|
162 | fi
|
---|
163 |
|
---|
164 | if [ $EUID -eq 0 ] ; then
|
---|
165 | pathappend /usr/sbin
|
---|
166 | if [ ! -L /sbin ]; then
|
---|
167 | pathappend /sbin
|
---|
168 | fi
|
---|
169 | unset HISTFILE
|
---|
170 | fi
|
---|
171 |
|
---|
172 | # Setup some environment variables.
|
---|
173 | export HISTSIZE=1000
|
---|
174 | export HISTIGNORE="&:[bf]g:exit"
|
---|
175 |
|
---|
176 | # Set some defaults for graphical systems
|
---|
177 | export XDG_DATA_DIRS=${XDG_DATA_DIRS:-/usr/share/}
|
---|
178 | export XDG_CONFIG_DIRS=${XDG_CONFIG_DIRS:-/etc/xdg/}
|
---|
179 | export XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR:-/tmp/xdg-$USER}
|
---|
180 |
|
---|
181 | # Setup a red prompt for root and a green one for users.
|
---|
182 | NORMAL="\[\e[0m\]"
|
---|
183 | RED="\[\e[1;31m\]"
|
---|
184 | GREEN="\[\e[1;32m\]"
|
---|
185 | if [[ $EUID == 0 ]] ; then
|
---|
186 | PS1="$RED\u [ $NORMAL\w$RED ]# $NORMAL"
|
---|
187 | else
|
---|
188 | PS1="$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL"
|
---|
189 | fi
|
---|
190 |
|
---|
191 | for script in /etc/profile.d/*.sh ; do
|
---|
192 | if [ -r $script ] ; then
|
---|
193 | . $script
|
---|
194 | fi
|
---|
195 | done
|
---|
196 |
|
---|
197 | unset script RED GREEN NORMAL
|
---|
198 |
|
---|
199 | # End /etc/profile</literal>
|
---|
200 | EOF</userinput></screen>
|
---|
201 |
|
---|
202 | <sect3 id="etc-profile.d">
|
---|
203 | <title>The /etc/profile.d Directory</title>
|
---|
204 |
|
---|
205 | <indexterm zone="postlfs-config-profile etc-profile.d">
|
---|
206 | <primary sortas="e-etc-profile.d">/etc/profile.d</primary>
|
---|
207 | </indexterm>
|
---|
208 |
|
---|
209 | <para>
|
---|
210 | Now create the <filename class='directory'>/etc/profile.d</filename>
|
---|
211 | directory, where the individual initialization scripts are placed:
|
---|
212 | </para>
|
---|
213 |
|
---|
214 | <screen role="root"><userinput>install --directory --mode=0755 --owner=root --group=root /etc/profile.d</userinput></screen>
|
---|
215 |
|
---|
216 | </sect3>
|
---|
217 |
|
---|
218 | <sect3 id="etc-profile.d-bash-completion.sh">
|
---|
219 | <title>/etc/profile.d/bash_completion.sh</title>
|
---|
220 |
|
---|
221 | <indexterm zone="postlfs-config-profile etc-profile.d-bash-completion.sh">
|
---|
222 | <primary sortas="e-etc-profile.d-bash-completion.sh">/etc/profile.d/bash_completion.sh</primary>
|
---|
223 | </indexterm>
|
---|
224 |
|
---|
225 | <note>
|
---|
226 | <para>
|
---|
227 | Using the bash completion script below is controversial. Not all
|
---|
228 | users like it. It adds many (usually over 1000) lines to the bash
|
---|
229 | environment and makes it difficult to use the 'set' command to
|
---|
230 | examine simple environment variables. Omitting this script does
|
---|
231 | not interfere with the ability of bash to use the tab key for file
|
---|
232 | name completion.
|
---|
233 | </para>
|
---|
234 | </note>
|
---|
235 |
|
---|
236 | <para>
|
---|
237 | This script imports bash completion scripts, installed by many
|
---|
238 | other BLFS packages, to allow TAB command line completion.
|
---|
239 | </para>
|
---|
240 |
|
---|
241 | <screen role="root"><userinput>cat > /etc/profile.d/bash_completion.sh << "EOF"
|
---|
242 | <literal># Begin /etc/profile.d/bash_completion.sh
|
---|
243 | # Import bash completion scripts
|
---|
244 |
|
---|
245 | # If the bash-completion package is installed, use its configuration instead
|
---|
246 | if [ -f /usr/share/bash-completion/bash_completion ]; then
|
---|
247 |
|
---|
248 | # Check for interactive bash and that we haven't already been sourced.
|
---|
249 | if [ -n "${BASH_VERSION-}" -a -n "${PS1-}" -a -z "${BASH_COMPLETION_VERSINFO-}" ]; then
|
---|
250 |
|
---|
251 | # Check for recent enough version of bash.
|
---|
252 | if [ ${BASH_VERSINFO[0]} -gt 4 ] || \
|
---|
253 | [ ${BASH_VERSINFO[0]} -eq 4 -a ${BASH_VERSINFO[1]} -ge 1 ]; then
|
---|
254 | [ -r "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion" ] && \
|
---|
255 | . "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion"
|
---|
256 | if shopt -q progcomp && [ -r /usr/share/bash-completion/bash_completion ]; then
|
---|
257 | # Source completion code.
|
---|
258 | . /usr/share/bash-completion/bash_completion
|
---|
259 | fi
|
---|
260 | fi
|
---|
261 | fi
|
---|
262 |
|
---|
263 | else
|
---|
264 |
|
---|
265 | # bash-completions are not installed, use only bash completion directory
|
---|
266 | if shopt -q progcomp; then
|
---|
267 | for script in /etc/bash_completion.d/* ; do
|
---|
268 | if [ -r $script ] ; then
|
---|
269 | . $script
|
---|
270 | fi
|
---|
271 | done
|
---|
272 | fi
|
---|
273 | fi
|
---|
274 |
|
---|
275 | # End /etc/profile.d/bash_completion.sh</literal>
|
---|
276 | EOF</userinput></screen>
|
---|
277 | <para>
|
---|
278 | Make sure that the directory exists:
|
---|
279 | </para>
|
---|
280 |
|
---|
281 | <screen role="root"><userinput>install --directory --mode=0755 --owner=root --group=root /etc/bash_completion.d</userinput></screen>
|
---|
282 |
|
---|
283 | <para>
|
---|
284 | For a more complete installation, see
|
---|
285 | <ulink url="&blfs-wiki;/bash-shell-startup-files#bash-completions"/>.
|
---|
286 | </para>
|
---|
287 |
|
---|
288 | </sect3>
|
---|
289 |
|
---|
290 | <sect3 id="etc-profile.d-dircolors.sh">
|
---|
291 | <title>/etc/profile.d/dircolors.sh</title>
|
---|
292 |
|
---|
293 | <indexterm zone="postlfs-config-profile etc-profile.d-dircolors.sh">
|
---|
294 | <primary sortas="e-etc-profile.d-dircolors.sh">/etc/profile.d/dircolors.sh</primary>
|
---|
295 | </indexterm>
|
---|
296 |
|
---|
297 | <para>
|
---|
298 | This script uses the <filename>~/.dircolors</filename> and
|
---|
299 | <filename>/etc/dircolors</filename> files to control the colors of
|
---|
300 | file names in a directory listing. They control colorized output of
|
---|
301 | things like <command>ls --color</command>. The explanation of how to
|
---|
302 | initialize these files is at the end of this section.
|
---|
303 | </para>
|
---|
304 |
|
---|
305 | <screen role="root"><userinput>cat > /etc/profile.d/dircolors.sh << "EOF"
|
---|
306 | <literal># Setup for /bin/ls and /bin/grep to support color, the alias is in /etc/bashrc.
|
---|
307 | if [ -f "/etc/dircolors" ] ; then
|
---|
308 | eval $(dircolors -b /etc/dircolors)
|
---|
309 | fi
|
---|
310 |
|
---|
311 | if [ -f "$HOME/.dircolors" ] ; then
|
---|
312 | eval $(dircolors -b $HOME/.dircolors)
|
---|
313 | fi
|
---|
314 |
|
---|
315 | alias ls='ls --color=auto'
|
---|
316 | alias grep='grep --color=auto'</literal>
|
---|
317 | EOF</userinput></screen>
|
---|
318 |
|
---|
319 | </sect3>
|
---|
320 |
|
---|
321 | <sect3 id="extrapaths.sh">
|
---|
322 | <title>/etc/profile.d/extrapaths.sh</title>
|
---|
323 |
|
---|
324 | <indexterm zone="postlfs-config-profile extrapaths.sh">
|
---|
325 | <primary sortas="e-etc-profile.d-extrapaths.sh">/etc/profile.d/extrapaths.sh</primary>
|
---|
326 | </indexterm>
|
---|
327 |
|
---|
328 | <para>
|
---|
329 | This script adds some useful paths to the <envar>PATH</envar> and
|
---|
330 | can be used to customize other PATH related environment variables
|
---|
331 | (e.g. LD_LIBRARY_PATH, etc) that may be needed for all users.
|
---|
332 | </para>
|
---|
333 |
|
---|
334 | <screen role="root"><userinput>cat > /etc/profile.d/extrapaths.sh << "EOF"
|
---|
335 | <literal>if [ -d /usr/local/lib/pkgconfig ] ; then
|
---|
336 | pathappend /usr/local/lib/pkgconfig PKG_CONFIG_PATH
|
---|
337 | fi
|
---|
338 | if [ -d /usr/local/bin ]; then
|
---|
339 | pathprepend /usr/local/bin
|
---|
340 | fi
|
---|
341 | if [ -d /usr/local/sbin -a $EUID -eq 0 ]; then
|
---|
342 | pathprepend /usr/local/sbin
|
---|
343 | fi
|
---|
344 |
|
---|
345 | if [ -d /usr/local/share ]; then
|
---|
346 | pathprepend /usr/local/share XDG_DATA_DIRS
|
---|
347 | fi
|
---|
348 |
|
---|
349 | # Set some defaults before other applications add to these paths.
|
---|
350 | pathappend /usr/share/man MANPATH
|
---|
351 | pathappend /usr/share/info INFOPATH</literal>
|
---|
352 | EOF</userinput></screen>
|
---|
353 |
|
---|
354 | </sect3>
|
---|
355 |
|
---|
356 | <sect3 id="readline.sh">
|
---|
357 | <title>/etc/profile.d/readline.sh</title>
|
---|
358 |
|
---|
359 | <indexterm zone="postlfs-config-profile readline.sh">
|
---|
360 | <primary sortas="e-etc-profile.d-readline.sh">/etc/profile.d/readline.sh</primary>
|
---|
361 | </indexterm>
|
---|
362 |
|
---|
363 | <para>
|
---|
364 | This script sets up the default <filename>inputrc</filename>
|
---|
365 | configuration file. If the user does not have individual settings, it
|
---|
366 | uses the global file.
|
---|
367 | </para>
|
---|
368 |
|
---|
369 | <screen role="root"><userinput>cat > /etc/profile.d/readline.sh << "EOF"
|
---|
370 | <literal># Setup the INPUTRC environment variable.
|
---|
371 | if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ] ; then
|
---|
372 | INPUTRC=/etc/inputrc
|
---|
373 | fi
|
---|
374 | export INPUTRC</literal>
|
---|
375 | EOF</userinput></screen>
|
---|
376 |
|
---|
377 | </sect3>
|
---|
378 |
|
---|
379 | <sect3 id="umask.sh">
|
---|
380 | <title>/etc/profile.d/umask.sh</title>
|
---|
381 |
|
---|
382 | <indexterm zone="postlfs-config-profile umask.sh">
|
---|
383 | <primary sortas="e-etc-profile.d-umask.sh">/etc/profile.d/umask.sh</primary>
|
---|
384 | </indexterm>
|
---|
385 |
|
---|
386 | <para>
|
---|
387 | Setting the <command>umask</command> value is important for security.
|
---|
388 | Here the default group write permissions are turned off for system
|
---|
389 | users and when the user name and group name are not the same.
|
---|
390 | </para>
|
---|
391 |
|
---|
392 | <screen role="root"><userinput>cat > /etc/profile.d/umask.sh << "EOF"
|
---|
393 | <literal># By default, the umask should be set.
|
---|
394 | if [ "$(id -gn)" = "$(id -un)" -a $EUID -gt 99 ] ; then
|
---|
395 | umask 002
|
---|
396 | else
|
---|
397 | umask 022
|
---|
398 | fi</literal>
|
---|
399 | EOF</userinput></screen>
|
---|
400 |
|
---|
401 | </sect3>
|
---|
402 |
|
---|
403 | <!-- This is handled in the Xorg section of the book
|
---|
404 | <sect3 id="X.sh">
|
---|
405 | <title>/etc/profile.d/X.sh</title>
|
---|
406 |
|
---|
407 | <indexterm zone="postlfs-config-profile X.sh">
|
---|
408 | <primary sortas="e-etc-profile.d-X.sh">/etc/profile.d/X.sh</primary>
|
---|
409 | </indexterm>
|
---|
410 |
|
---|
411 | <para>
|
---|
412 | If <application>X</application> is installed, the <envar>PATH</envar>
|
---|
413 | and <envar>PKG_CONFIG_PATH</envar> variables are also updated.
|
---|
414 | </para>
|
---|
415 |
|
---|
416 | <screen role="root"><userinput>cat > /etc/profile.d/X.sh << "EOF"
|
---|
417 | <literal>if [ -x /usr/X11R6/bin/X ]; then
|
---|
418 | pathappend /usr/X11R6/bin
|
---|
419 | fi
|
---|
420 | if [ -d /usr/X11R6/lib/pkgconfig ] ; then
|
---|
421 | pathappend /usr/X11R6/lib/pkgconfig PKG_CONFIG_PATH
|
---|
422 | fi</literal>
|
---|
423 | EOF</userinput></screen>
|
---|
424 |
|
---|
425 | </sect3>
|
---|
426 | -->
|
---|
427 | <sect3 id="i18n.sh">
|
---|
428 | <!-- This is handled system wide on systemd but LANG is not exported to
|
---|
429 | the environment, hence it's return...need to add additional text for
|
---|
430 | systemd only -->
|
---|
431 | <title>/etc/profile.d/i18n.sh</title>
|
---|
432 |
|
---|
433 | <indexterm zone="postlfs-config-profile i18n.sh">
|
---|
434 | <primary sortas="e-etc-profile.d-i18n.sh">/etc/profile.d/i18n.sh</primary>
|
---|
435 | </indexterm>
|
---|
436 |
|
---|
437 | <para>
|
---|
438 | This script sets an environment variable necessary for
|
---|
439 | native language support. A full discussion on determining this
|
---|
440 | variable can be found on the <ulink
|
---|
441 | url="&lfs-root;/chapter09/profile.html">LFS Bash Shell
|
---|
442 | Startup Files</ulink> page.
|
---|
443 | </para>
|
---|
444 |
|
---|
445 | <screen role="root" revision="sysv"><userinput>cat > /etc/profile.d/i18n.sh << "EOF"
|
---|
446 | <literal># Set up i18n variables
|
---|
447 | export LANG=<replaceable><ll></replaceable>_<replaceable><CC></replaceable>.<replaceable><charmap></replaceable><replaceable><@modifiers></replaceable></literal>
|
---|
448 | EOF</userinput></screen>
|
---|
449 |
|
---|
450 | <screen role="root" revision="systemd"><userinput>cat > /etc/profile.d/i18n.sh << "EOF"
|
---|
451 | <literal># Set up i18n variables
|
---|
452 | . /etc/locale.conf
|
---|
453 | export LANG</literal>
|
---|
454 | EOF</userinput></screen>
|
---|
455 |
|
---|
456 | </sect3>
|
---|
457 |
|
---|
458 | <sect3>
|
---|
459 | <title>Other Initialization Values</title>
|
---|
460 |
|
---|
461 | <para>
|
---|
462 | Other initialization can easily be added to the
|
---|
463 | <filename>profile</filename> by adding additional scripts to the
|
---|
464 | <filename class='directory'>/etc/profile.d</filename> directory.
|
---|
465 | </para>
|
---|
466 |
|
---|
467 | </sect3>
|
---|
468 |
|
---|
469 | </sect2>
|
---|
470 |
|
---|
471 | <sect2 id="etc-bashrc-profile">
|
---|
472 | <title>/etc/bashrc</title>
|
---|
473 |
|
---|
474 | <indexterm zone="postlfs-config-profile etc-bashrc-profile">
|
---|
475 | <primary sortas="e-etc-bashrc">/etc/bashrc</primary>
|
---|
476 | </indexterm>
|
---|
477 |
|
---|
478 | <para>
|
---|
479 | Here is a base <filename>/etc/bashrc</filename>. Comments in the
|
---|
480 | file should explain everything you need.
|
---|
481 | </para>
|
---|
482 |
|
---|
483 | <screen role="root"><userinput>cat > /etc/bashrc << "EOF"
|
---|
484 | <literal># Begin /etc/bashrc
|
---|
485 | # Written for Beyond Linux From Scratch
|
---|
486 | # by James Robertson <jameswrobertson@earthlink.net>
|
---|
487 | # updated by Bruce Dubbs <bdubbs@&lfs-domainname;>
|
---|
488 |
|
---|
489 | # System wide aliases and functions.
|
---|
490 |
|
---|
491 | # System wide environment variables and startup programs should go into
|
---|
492 | # /etc/profile. Personal environment variables and startup programs
|
---|
493 | # should go into ~/.bash_profile. Personal aliases and functions should
|
---|
494 | # go into ~/.bashrc
|
---|
495 |
|
---|
496 | # Provides colored /bin/ls and /bin/grep commands. Used in conjunction
|
---|
497 | # with code in /etc/profile.
|
---|
498 |
|
---|
499 | alias ls='ls --color=auto'
|
---|
500 | alias grep='grep --color=auto'
|
---|
501 |
|
---|
502 | # Provides prompt for non-login shells, specifically shells started
|
---|
503 | # in the X environment. [Review the LFS archive thread titled
|
---|
504 | # PS1 Environment Variable for a great case study behind this script
|
---|
505 | # addendum.]
|
---|
506 |
|
---|
507 | NORMAL="\[\e[0m\]"
|
---|
508 | RED="\[\e[1;31m\]"
|
---|
509 | GREEN="\[\e[1;32m\]"
|
---|
510 | if [[ $EUID == 0 ]] ; then
|
---|
511 | PS1="$RED\u [ $NORMAL\w$RED ]# $NORMAL"
|
---|
512 | else
|
---|
513 | PS1="$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL"
|
---|
514 | fi
|
---|
515 |
|
---|
516 | unset RED GREEN NORMAL
|
---|
517 |
|
---|
518 | # End /etc/bashrc</literal>
|
---|
519 | EOF</userinput></screen>
|
---|
520 |
|
---|
521 | </sect2>
|
---|
522 |
|
---|
523 | <sect2 id="bash_profile-profile">
|
---|
524 | <title>~/.bash_profile</title>
|
---|
525 |
|
---|
526 | <indexterm zone="postlfs-config-profile bash_profile-profile">
|
---|
527 | <primary sortas="e-AA.bash_profile">~/.bash_profile</primary>
|
---|
528 | </indexterm>
|
---|
529 |
|
---|
530 | <para>
|
---|
531 | Here is a base <filename>~/.bash_profile</filename>. If you want each
|
---|
532 | new user to have this file automatically, just change the output of
|
---|
533 | the command to <filename>/etc/skel/.bash_profile</filename> and check the
|
---|
534 | permissions after the command is run. You can then copy <filename>
|
---|
535 | /etc/skel/.bash_profile</filename> to the home directories of already
|
---|
536 | existing users, including <systemitem class="username">root</systemitem>,
|
---|
537 | and set the owner and group appropriately.
|
---|
538 | </para>
|
---|
539 |
|
---|
540 | <screen><userinput>cat > ~/.bash_profile << "EOF"
|
---|
541 | <literal># Begin ~/.bash_profile
|
---|
542 | # Written for Beyond Linux From Scratch
|
---|
543 | # by James Robertson <jameswrobertson@earthlink.net>
|
---|
544 | # updated by Bruce Dubbs <bdubbs@&lfs-domainname;>
|
---|
545 |
|
---|
546 | # Personal environment variables and startup programs.
|
---|
547 |
|
---|
548 | # Personal aliases and functions should go in ~/.bashrc. System wide
|
---|
549 | # environment variables and startup programs are in /etc/profile.
|
---|
550 | # System wide aliases and functions are in /etc/bashrc.
|
---|
551 |
|
---|
552 | if [ -f "$HOME/.bashrc" ] ; then
|
---|
553 | source $HOME/.bashrc
|
---|
554 | fi
|
---|
555 |
|
---|
556 | if [ -d "$HOME/bin" ] ; then
|
---|
557 | pathprepend $HOME/bin
|
---|
558 | fi
|
---|
559 |
|
---|
560 | # Having . in the PATH is dangerous
|
---|
561 | #if [ $EUID -gt 99 ]; then
|
---|
562 | # pathappend .
|
---|
563 | #fi
|
---|
564 |
|
---|
565 | # End ~/.bash_profile</literal>
|
---|
566 | EOF</userinput></screen>
|
---|
567 |
|
---|
568 | </sect2>
|
---|
569 |
|
---|
570 | <sect2 id="dot_profile-profile">
|
---|
571 | <title>~/.profile</title>
|
---|
572 |
|
---|
573 | <indexterm zone="postlfs-config-profile dot_profile-profile">
|
---|
574 | <primary sortas="e-AA.dot_profile">~/.profile</primary>
|
---|
575 | </indexterm>
|
---|
576 |
|
---|
577 | <para>
|
---|
578 | Here is a base <filename>~/.profile</filename>. The comments and
|
---|
579 | instructions for using <filename class="directory">/etc/skel</filename>
|
---|
580 | for <filename>.bash_profile</filename> above also apply here. Only the
|
---|
581 | target file names are different.
|
---|
582 | </para>
|
---|
583 |
|
---|
584 | <screen><userinput>cat > ~/.profile << "EOF"
|
---|
585 | <literal># Begin ~/.profile
|
---|
586 | # Personal environment variables and startup programs.
|
---|
587 |
|
---|
588 | if [ -d "$HOME/bin" ] ; then
|
---|
589 | pathprepend $HOME/bin
|
---|
590 | fi
|
---|
591 |
|
---|
592 | # Set up user specific i18n variables
|
---|
593 | #export LANG=<replaceable><ll></replaceable>_<replaceable><CC></replaceable>.<replaceable><charmap></replaceable><replaceable><@modifiers></replaceable>
|
---|
594 |
|
---|
595 | # End ~/.profile</literal>
|
---|
596 | EOF</userinput></screen>
|
---|
597 |
|
---|
598 | </sect2>
|
---|
599 |
|
---|
600 | <sect2 id="bashrc-profile">
|
---|
601 | <title>~/.bashrc</title>
|
---|
602 |
|
---|
603 | <indexterm zone="postlfs-config-profile bashrc-profile">
|
---|
604 | <primary sortas="e-AA.bashrc">~/.bashrc</primary>
|
---|
605 | </indexterm>
|
---|
606 |
|
---|
607 | <para>
|
---|
608 | Here is a base <filename>~/.bashrc</filename>.
|
---|
609 | </para>
|
---|
610 |
|
---|
611 | <screen><userinput>cat > ~/.bashrc << "EOF"
|
---|
612 | <literal># Begin ~/.bashrc
|
---|
613 | # Written for Beyond Linux From Scratch
|
---|
614 | # by James Robertson <jameswrobertson@earthlink.net>
|
---|
615 |
|
---|
616 | # Personal aliases and functions.
|
---|
617 |
|
---|
618 | # Personal environment variables and startup programs should go in
|
---|
619 | # ~/.bash_profile. System wide environment variables and startup
|
---|
620 | # programs are in /etc/profile. System wide aliases and functions are
|
---|
621 | # in /etc/bashrc.
|
---|
622 |
|
---|
623 | if [ -f "/etc/bashrc" ] ; then
|
---|
624 | source /etc/bashrc
|
---|
625 | fi
|
---|
626 |
|
---|
627 | # Set up user specific i18n variables
|
---|
628 | #export LANG=<replaceable><ll></replaceable>_<replaceable><CC></replaceable>.<replaceable><charmap></replaceable><replaceable><@modifiers></replaceable>
|
---|
629 |
|
---|
630 | # End ~/.bashrc</literal>
|
---|
631 | EOF</userinput></screen>
|
---|
632 |
|
---|
633 | </sect2>
|
---|
634 |
|
---|
635 |
|
---|
636 | <sect2 id="bash_logout-profile">
|
---|
637 | <title>~/.bash_logout</title>
|
---|
638 |
|
---|
639 | <indexterm zone="postlfs-config-profile bash_logout-profile">
|
---|
640 | <primary sortas="e-AA.bash_logout">~/.bash_logout</primary>
|
---|
641 | </indexterm>
|
---|
642 |
|
---|
643 | <para>
|
---|
644 | This is an empty <filename>~/.bash_logout</filename> that can be used as
|
---|
645 | a template. You will notice that the base <filename>~/.bash_logout
|
---|
646 | </filename> does not include a <userinput>clear</userinput> command.
|
---|
647 | This is because the clear is handled in the
|
---|
648 | <filename>/etc/issue</filename> file.
|
---|
649 | </para>
|
---|
650 |
|
---|
651 | <screen><userinput>cat > ~/.bash_logout << "EOF"
|
---|
652 | <literal># Begin ~/.bash_logout
|
---|
653 | # Written for Beyond Linux From Scratch
|
---|
654 | # by James Robertson <jameswrobertson@earthlink.net>
|
---|
655 |
|
---|
656 | # Personal items to perform on logout.
|
---|
657 |
|
---|
658 | # End ~/.bash_logout</literal>
|
---|
659 | EOF</userinput></screen>
|
---|
660 |
|
---|
661 | </sect2>
|
---|
662 |
|
---|
663 |
|
---|
664 | <sect2 id="etc-dircolors-profile">
|
---|
665 | <title>/etc/dircolors</title>
|
---|
666 |
|
---|
667 | <indexterm zone="postlfs-config-profile etc-dircolors-profile">
|
---|
668 | <primary sortas="e-etc-dircolors">/etc/dircolors</primary>
|
---|
669 | </indexterm>
|
---|
670 |
|
---|
671 | <indexterm zone="postlfs-config-profile etc-dircolors-profile">
|
---|
672 | <primary sortas="e-AA.dircolors">~/.dircolors</primary>
|
---|
673 | </indexterm>
|
---|
674 |
|
---|
675 | <para>
|
---|
676 | If you want to use the <filename>dircolors</filename> capability, then
|
---|
677 | run the following command. The <filename class="directory">/etc/skel
|
---|
678 | </filename> setup steps shown above also can be used here to provide
|
---|
679 | a <filename>~/.dircolors</filename> file when a new user is set up.
|
---|
680 | As before, just change the output file name on the following command
|
---|
681 | and assure the permissions, owner, and group are correct on the files
|
---|
682 | created and/or copied.
|
---|
683 | </para>
|
---|
684 |
|
---|
685 | <screen role="root"><userinput>dircolors -p > /etc/dircolors</userinput></screen>
|
---|
686 |
|
---|
687 | <para>
|
---|
688 | If you wish to customize the colors used for different file types, you
|
---|
689 | can edit the <filename>/etc/dircolors</filename> file. The instructions
|
---|
690 | for setting the colors are embedded in the file.
|
---|
691 | </para>
|
---|
692 |
|
---|
693 |
|
---|
694 | <para>
|
---|
695 | Finally, Ian Macdonald has written an excellent collection of tips and
|
---|
696 | tricks to enhance your shell environment. You can read it online at
|
---|
697 | <ulink url="http://www.caliban.org/bash/index.shtml"/>.
|
---|
698 | </para>
|
---|
699 |
|
---|
700 | </sect2>
|
---|
701 |
|
---|
702 | </sect1>
|
---|