source: postlfs/config/profile.xml@ 6f36554

10.0 10.1 11.0 11.1 8.1 8.2 8.3 8.4 9.0 9.1 basic bdubbs/svn elogind lazarus perl-modules qt5new trunk upgradedb xry111/intltool xry111/test-20220226
Last change on this file since 6f36554 was 6f36554, checked in by DJ Lucas <dj@…>, 5 years ago

Add ~/.profile to bash shell startup files.

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

  • Property mode set to 100644
File size: 18.9 KB
Line 
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 <sect2 id="etc-profile-profile">
72 <title>/etc/profile</title>
73
74 <indexterm zone="postlfs-config-profile etc-profile-profile">
75 <primary sortas="e-etc-profile">/etc/profile</primary>
76 </indexterm>
77
78 <para>Here is a base <filename>/etc/profile</filename>. This file starts by
79 setting up some helper functions and some basic parameters. It specifies some
80 <command>bash</command> history parameters and, for security purposes,
81 disables keeping a permanent history file for the <systemitem
82 class="username">root</systemitem> user. It also sets a
83 default user prompt. It then calls small, single purpose scripts in the
84 <filename class='directory'>/etc/profile.d</filename> directory to provide most
85 of the initialization.</para>
86
87 <para>For more information on the escape sequences you can use for your prompt
88 (i.e., the <envar>PS1</envar> environment variable) see <command>info
89 bash</command> -- <emphasis role="strong">Node: Printing a
90 Prompt</emphasis>.</para>
91
92<screen role="root"><?dbfo keep-together="auto"?><userinput>cat &gt; /etc/profile &lt;&lt; "EOF"
93<literal># Begin /etc/profile
94# Written for Beyond Linux From Scratch
95# by James Robertson &lt;jameswrobertson@earthlink.net&gt;
96# modifications by Dagmar d'Surreal &lt;rivyqntzne@pbzpnfg.arg&gt;
97
98# System wide environment variables and startup programs.
99
100# System wide aliases and functions should go in /etc/bashrc. Personal
101# environment variables and startup programs should go into
102# ~/.bash_profile. Personal aliases and functions should go into
103# ~/.bashrc.
104
105# Functions to help us manage paths. Second argument is the name of the
106# path variable to be modified (default: PATH)
107pathremove () {
108 local IFS=':'
109 local NEWPATH
110 local DIR
111 local PATHVARIABLE=${2:-PATH}
112 for DIR in ${!PATHVARIABLE} ; do
113 if [ "$DIR" != "$1" ] ; then
114 NEWPATH=${NEWPATH:+$NEWPATH:}$DIR
115 fi
116 done
117 export $PATHVARIABLE="$NEWPATH"
118}
119
120pathprepend () {
121 pathremove $1 $2
122 local PATHVARIABLE=${2:-PATH}
123 export $PATHVARIABLE="$1${!PATHVARIABLE:+:${!PATHVARIABLE}}"
124}
125
126pathappend () {
127 pathremove $1 $2
128 local PATHVARIABLE=${2:-PATH}
129 export $PATHVARIABLE="${!PATHVARIABLE:+${!PATHVARIABLE}:}$1"
130}
131
132export -f pathremove pathprepend pathappend
133
134# Set the initial path
135export PATH=/bin:/usr/bin
136
137if [ $EUID -eq 0 ] ; then
138 pathappend /sbin:/usr/sbin
139 unset HISTFILE
140fi
141
142# Setup some environment variables.
143export HISTSIZE=1000
144export HISTIGNORE="&amp;:[bf]g:exit"
145
146# Set some defaults for graphical systems
147export XDG_DATA_DIRS=/usr/share/
148export XDG_CONFIG_DIRS=/etc/xdg/
149
150# Setup a red prompt for root and a green one for users.
151NORMAL="\[\e[0m\]"
152RED="\[\e[1;31m\]"
153GREEN="\[\e[1;32m\]"
154if [[ $EUID == 0 ]] ; then
155 PS1="$RED\u [ $NORMAL\w$RED ]# $NORMAL"
156else
157 PS1="$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL"
158fi
159
160for script in /etc/profile.d/*.sh ; do
161 if [ -r $script ] ; then
162 . $script
163 fi
164done
165
166unset script RED GREEN NORMAL
167
168# End /etc/profile</literal>
169EOF</userinput></screen>
170
171 <sect3 id="etc-profile.d">
172 <title>The /etc/profile.d Directory</title>
173
174 <indexterm zone="postlfs-config-profile etc-profile.d">
175 <primary sortas="e-etc-profile.d">/etc/profile.d</primary>
176 </indexterm>
177
178 <para>Now create the <filename class='directory'>/etc/profile.d</filename>
179 directory, where the individual initialization scripts are placed:</para>
180
181<screen role="root"><userinput>install --directory --mode=0755 --owner=root --group=root /etc/profile.d</userinput></screen>
182
183 </sect3>
184
185 <sect3 id="etc-profile.d-dircolors.sh">
186 <title>/etc/profile.d/dircolors.sh</title>
187
188 <indexterm zone="postlfs-config-profile etc-profile.d-dircolors.sh">
189 <primary sortas="e-etc-profile.d-dircolors.sh">/etc/profile.d/dircolors.sh</primary>
190 </indexterm>
191
192 <para>This script uses the <filename>~/.dircolors</filename> and
193 <filename>/etc/dircolors</filename> files to control the colors of file names in a
194 directory listing. They control colorized output of things like <command>ls
195 --color</command>. The explanation of how to initialize these files is at the
196 end of this section.</para>
197
198<screen role="root"><userinput>cat &gt; /etc/profile.d/dircolors.sh &lt;&lt; "EOF"
199<literal># Setup for /bin/ls and /bin/grep to support color, the alias is in /etc/bashrc.
200if [ -f "/etc/dircolors" ] ; then
201 eval $(dircolors -b /etc/dircolors)
202fi
203
204if [ -f "$HOME/.dircolors" ] ; then
205 eval $(dircolors -b $HOME/.dircolors)
206fi
207
208alias ls='ls --color=auto'
209alias grep='grep --color=auto'</literal>
210EOF</userinput></screen>
211
212 </sect3>
213
214 <sect3 id="extrapaths.sh">
215 <title>/etc/profile.d/extrapaths.sh</title>
216
217 <indexterm zone="postlfs-config-profile extrapaths.sh">
218 <primary sortas="e-etc-profile.d-extrapaths.sh">/etc/profile.d/extrapaths.sh</primary>
219 </indexterm>
220
221 <para>This script adds some useful paths to the <envar>PATH</envar> and
222 can be used to customize other PATH related environment variables
223 (e.g. LD_LIBRARY_PATH, etc) that may be needed for all users.</para>
224
225<screen role="root"><userinput>cat &gt; /etc/profile.d/extrapaths.sh &lt;&lt; "EOF"
226<literal>if [ -d /usr/local/lib/pkgconfig ] ; then
227 pathappend /usr/local/lib/pkgconfig PKG_CONFIG_PATH
228fi
229if [ -d /usr/local/bin ]; then
230 pathprepend /usr/local/bin
231fi
232if [ -d /usr/local/sbin -a $EUID -eq 0 ]; then
233 pathprepend /usr/local/sbin
234fi
235
236# Set some defaults before other applications add to these paths.
237pathappend /usr/share/man MANPATH
238pathappend /usr/share/info INFOPATH</literal>
239EOF</userinput></screen>
240
241 </sect3>
242
243 <sect3 id="readline.sh">
244 <title>/etc/profile.d/readline.sh</title>
245
246 <indexterm zone="postlfs-config-profile readline.sh">
247 <primary sortas="e-etc-profile.d-readline.sh">/etc/profile.d/readline.sh</primary>
248 </indexterm>
249
250 <para>This script sets up the default <filename>inputrc</filename>
251 configuration file. If the user does not have individual settings, it uses the
252 global file.</para>
253
254<screen role="root"><userinput>cat &gt; /etc/profile.d/readline.sh &lt;&lt; "EOF"
255<literal># Setup the INPUTRC environment variable.
256if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ] ; then
257 INPUTRC=/etc/inputrc
258fi
259export INPUTRC</literal>
260EOF</userinput></screen>
261
262 </sect3>
263
264 <sect3 id="umask.sh">
265 <title>/etc/profile.d/umask.sh</title>
266
267 <indexterm zone="postlfs-config-profile umask.sh">
268 <primary sortas="e-etc-profile.d-umask.sh">/etc/profile.d/umask.sh</primary>
269 </indexterm>
270
271 <para>Setting the <command>umask</command> value is important for security.
272 Here the default group write permissions are turned off for system users and when
273 the user name and group name are not the same.</para>
274
275<screen role="root"><userinput>cat &gt; /etc/profile.d/umask.sh &lt;&lt; "EOF"
276<literal># By default, the umask should be set.
277if [ "$(id -gn)" = "$(id -un)" -a $EUID -gt 99 ] ; then
278 umask 002
279else
280 umask 022
281fi</literal>
282EOF</userinput></screen>
283
284 </sect3>
285
286<!-- This is handled in the Xorg section of the book
287 <sect3 id="X.sh">
288 <title>/etc/profile.d/X.sh</title>
289
290 <indexterm zone="postlfs-config-profile X.sh">
291 <primary sortas="e-etc-profile.d-X.sh">/etc/profile.d/X.sh</primary>
292 </indexterm>
293
294 <para>If <application>X</application> is installed, the <envar>PATH</envar>
295 and <envar>PKG_CONFIG_PATH</envar> variables are also updated.</para>
296
297<screen role="root"><userinput>cat &gt; /etc/profile.d/X.sh &lt;&lt; "EOF"
298<literal>if [ -x /usr/X11R6/bin/X ]; then
299 pathappend /usr/X11R6/bin
300fi
301if [ -d /usr/X11R6/lib/pkgconfig ] ; then
302 pathappend /usr/X11R6/lib/pkgconfig PKG_CONFIG_PATH
303fi</literal>
304EOF</userinput></screen>
305
306 </sect3>
307-->
308 <sect3 id="i18n.sh">
309 <title>/etc/profile.d/i18n.sh</title>
310
311 <indexterm zone="postlfs-config-profile i18n.sh">
312 <primary sortas="e-etc-profile.d-i18n.sh">/etc/profile.d/i18n.sh</primary>
313 </indexterm>
314
315 <para>This script sets an environment variable necessary for
316 native language support. A full discussion on determining this
317 variable can be found on the <ulink
318 url="&lfs-root;/chapter07/profile.html">LFS Bash Shell
319 Startup Files</ulink> page.</para>
320
321<screen role="root"><userinput>cat &gt; /etc/profile.d/i18n.sh &lt;&lt; "EOF"
322<literal># Set up i18n variables
323export LANG=<replaceable>&lt;ll&gt;</replaceable>_<replaceable>&lt;CC&gt;</replaceable>.<replaceable>&lt;charmap&gt;</replaceable><replaceable>&lt;@modifiers&gt;</replaceable></literal>
324EOF</userinput></screen>
325
326 </sect3>
327
328 <sect3>
329 <title>Other Initialization Values</title>
330
331 <para>Other initialization can easily be added to the
332 <filename>profile</filename> by adding additional scripts to the
333 <filename class='directory'>/etc/profile.d</filename> directory.</para>
334
335 </sect3>
336
337 </sect2>
338
339 <sect2 id="etc-bashrc-profile">
340 <title>/etc/bashrc</title>
341
342 <indexterm zone="postlfs-config-profile etc-bashrc-profile">
343 <primary sortas="e-etc-bashrc">/etc/bashrc</primary>
344 </indexterm>
345
346 <para>Here is a base <filename>/etc/bashrc</filename>. Comments in the
347 file should explain everything you need.</para>
348
349<screen role="root"><userinput>cat &gt; /etc/bashrc &lt;&lt; "EOF"
350<literal># Begin /etc/bashrc
351# Written for Beyond Linux From Scratch
352# by James Robertson &lt;jameswrobertson@earthlink.net&gt;
353# updated by Bruce Dubbs &lt;bdubbs@&lfs-domainname;&gt;
354
355# System wide aliases and functions.
356
357# System wide environment variables and startup programs should go into
358# /etc/profile. Personal environment variables and startup programs
359# should go into ~/.bash_profile. Personal aliases and functions should
360# go into ~/.bashrc
361
362# Provides colored /bin/ls and /bin/grep commands. Used in conjunction
363# with code in /etc/profile.
364
365alias ls='ls --color=auto'
366alias grep='grep --color=auto'
367
368# Provides prompt for non-login shells, specifically shells started
369# in the X environment. [Review the LFS archive thread titled
370# PS1 Environment Variable for a great case study behind this script
371# addendum.]
372
373NORMAL="\[\e[0m\]"
374RED="\[\e[1;31m\]"
375GREEN="\[\e[1;32m\]"
376if [[ $EUID == 0 ]] ; then
377 PS1="$RED\u [ $NORMAL\w$RED ]# $NORMAL"
378else
379 PS1="$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL"
380fi
381
382unset RED GREEN NORMAL
383
384# End /etc/bashrc</literal>
385EOF</userinput></screen>
386
387 </sect2>
388
389 <sect2 id="bash_profile-profile">
390 <title>~/.bash_profile</title>
391
392 <indexterm zone="postlfs-config-profile bash_profile-profile">
393 <primary sortas="e-AA.bash_profile">~/.bash_profile</primary>
394 </indexterm>
395
396 <para>Here is a base <filename>~/.bash_profile</filename>. If you want each
397 new user to have this file automatically, just change the output of
398 the command to <filename>/etc/skel/.bash_profile</filename> and check the
399 permissions after the command is run. You can then copy
400 <filename>/etc/skel/.bash_profile</filename> to the home directories of already
401 existing users, including <systemitem class="username">root</systemitem>,
402 and set the owner and group appropriately.</para>
403
404<screen><userinput>cat &gt; ~/.bash_profile &lt;&lt; "EOF"
405<literal># Begin ~/.bash_profile
406# Written for Beyond Linux From Scratch
407# by James Robertson &lt;jameswrobertson@earthlink.net&gt;
408# updated by Bruce Dubbs &lt;bdubbs@&lfs-domainname;&gt;
409
410# Personal environment variables and startup programs.
411
412# Personal aliases and functions should go in ~/.bashrc. System wide
413# environment variables and startup programs are in /etc/profile.
414# System wide aliases and functions are in /etc/bashrc.
415
416if [ -f "$HOME/.bashrc" ] ; then
417 source $HOME/.bashrc
418fi
419
420if [ -d "$HOME/bin" ] ; then
421 pathprepend $HOME/bin
422fi
423
424# Having . in the PATH is dangerous
425#if [ $EUID -gt 99 ]; then
426# pathappend .
427#fi
428
429# End ~/.bash_profile</literal>
430EOF</userinput></screen>
431
432 </sect2>
433
434 <sect2 id="dot_profile-profile">
435 <title>~/.profile</title>
436
437 <indexterm zone="postlfs-config-profile dot_profile-profile">
438 <primary sortas="e-AA.dot_profile">~/.profile</primary>
439 </indexterm>
440
441 <para>Here is a base <filename>~/.profile</filename>. The comments and
442 instructions for using <filename class="directory">/etc/skel</filename> for
443 <filename>.bash_profile</filename> above also apply here. Only the target
444 file names are different.</para>
445
446<screen><userinput>cat &gt; ~/.profile &lt;&lt; "EOF"
447<literal># Begin ~/.profile
448# Personal environment variables and startup programs.
449
450if [ -d "$HOME/bin" ] ; then
451 pathprepend $HOME/bin
452fi
453
454# End ~/.profile</literal>
455EOF</userinput></screen>
456
457 </sect2>
458
459 <sect2 id="bashrc-profile">
460 <title>~/.bashrc</title>
461
462 <indexterm zone="postlfs-config-profile bashrc-profile">
463 <primary sortas="e-AA.bashrc">~/.bashrc</primary>
464 </indexterm>
465
466 <para>Here is a base <filename>~/.bashrc</filename>.</para>
467
468<screen><userinput>cat &gt; ~/.bashrc &lt;&lt; "EOF"
469<literal># Begin ~/.bashrc
470# Written for Beyond Linux From Scratch
471# by James Robertson &lt;jameswrobertson@earthlink.net&gt;
472
473# Personal aliases and functions.
474
475# Personal environment variables and startup programs should go in
476# ~/.bash_profile. System wide environment variables and startup
477# programs are in /etc/profile. System wide aliases and functions are
478# in /etc/bashrc.
479
480if [ -f "/etc/bashrc" ] ; then
481 source /etc/bashrc
482fi
483
484# End ~/.bashrc</literal>
485EOF</userinput></screen>
486
487 </sect2>
488
489
490 <sect2 id="bash_logout-profile">
491 <title>~/.bash_logout</title>
492
493 <indexterm zone="postlfs-config-profile bash_logout-profile">
494 <primary sortas="e-AA.bash_logout">~/.bash_logout</primary>
495 </indexterm>
496
497 <para>This is an empty <filename>~/.bash_logout</filename> that can be used as
498 a template. You will notice that the base <filename>~/.bash_logout</filename>
499 does not include a <userinput>clear</userinput> command. This is because the
500 clear is handled in the <filename>/etc/issue</filename> file.</para>
501
502<screen><userinput>cat &gt; ~/.bash_logout &lt;&lt; "EOF"
503<literal># Begin ~/.bash_logout
504# Written for Beyond Linux From Scratch
505# by James Robertson &lt;jameswrobertson@earthlink.net&gt;
506
507# Personal items to perform on logout.
508
509# End ~/.bash_logout</literal>
510EOF</userinput></screen>
511
512 </sect2>
513
514
515 <sect2 id="etc-dircolors-profile">
516 <title>/etc/dircolors</title>
517
518 <indexterm zone="postlfs-config-profile etc-dircolors-profile">
519 <primary sortas="e-etc-dircolors">/etc/dircolors</primary>
520 </indexterm>
521
522 <indexterm zone="postlfs-config-profile etc-dircolors-profile">
523 <primary sortas="e-AA.dircolors">~/.dircolors</primary>
524 </indexterm>
525
526 <para> If you want to use the <filename>dircolors</filename> capability,
527 then run the following command. The
528 <filename class="directory">/etc/skel</filename> setup steps shown above
529 also can be used here to provide a <filename>~/.dircolors</filename> file
530 when a new user is set up. As before, just change the output file name on
531 the following command and assure the permissions, owner, and group are
532 correct on the files created and/or copied.</para>
533
534<screen role="root"><userinput>dircolors -p > /etc/dircolors</userinput></screen>
535
536 <para>If you wish to customize the colors used for different file types,
537 you can edit the <filename>/etc/dircolors</filename> file. The instructions
538 for setting the colors are embedded in the file.</para>
539
540
541 <para>Finally, Ian Macdonald has written an excellent collection of tips and
542 tricks to enhance your shell environment. You can read it online at
543 <ulink url="http://www.caliban.org/bash/index.shtml"/>.</para>
544
545 </sect2>
546
547</sect1>
Note: See TracBrowser for help on using the repository browser.