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