[b32e803] | 1 | <?xml version="1.0" encoding="ISO-8859-1"?>
|
---|
| 2 | <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN" "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
|
---|
| 3 | <!ENTITY % general-entities SYSTEM "../general.ent">
|
---|
| 4 | %general-entities;
|
---|
| 5 | ]>
|
---|
| 6 | <sect1 id="ch-scripts-profile">
|
---|
| 7 | <title>The Bash Shell Startup Files</title>
|
---|
| 8 | <?dbhtml filename="profile.html"?>
|
---|
| 9 |
|
---|
[f67f5cf] | 10 | <indexterm zone="ch-scripts-profile"><primary sortas="e-/etc/profile">/etc/profile</primary></indexterm>
|
---|
| 11 |
|
---|
| 12 | <para>The shell program <command>/bin/bash</command> (hereafter
|
---|
[5ba3d1d] | 13 | referred to as <quote>the shell</quote>) uses a collection of startup
|
---|
| 14 | files to help create an environment to run in. Each file has a
|
---|
| 15 | specific use and may affect login and interactive environments
|
---|
| 16 | differently. The files in the <filename
|
---|
| 17 | class="directory">/etc</filename> directory provide global settings.
|
---|
| 18 | If an equivalent file exists in the home directory, it may override
|
---|
| 19 | the global settings.</para>
|
---|
| 20 |
|
---|
| 21 | <para>An interactive login shell is started after a successful login,
|
---|
| 22 | using <command>/bin/login</command>, by reading the
|
---|
| 23 | <filename>/etc/passwd</filename> file. An interactive non-login shell
|
---|
| 24 | is started at the command-line (e.g.,
|
---|
| 25 | <prompt>[prompt]$</prompt><command>/bin/bash</command>). A
|
---|
| 26 | non-interactive shell is usually present when a shell script is
|
---|
| 27 | running. It is non-interactive because it is processing a script and
|
---|
| 28 | not waiting for user input between commands.</para>
|
---|
| 29 |
|
---|
[69993f4] | 30 | <para>For more information, see <command>info bash</command> - Nodes:
|
---|
[5ba3d1d] | 31 | Bash Startup Files and Interactive Shells.</para>
|
---|
[b32e803] | 32 |
|
---|
| 33 | <para>The files <filename>/etc/profile</filename> and
|
---|
[5ba3d1d] | 34 | <filename>~/.bash_profile</filename> are read when the shell is
|
---|
| 35 | invoked as an interactive login shell.</para>
|
---|
| 36 |
|
---|
| 37 | <para>A base <filename>/etc/profile</filename> below sets some
|
---|
| 38 | environment variables necessary for native language support. Setting
|
---|
| 39 | them properly results in:</para>
|
---|
[b32e803] | 40 |
|
---|
[181a690] | 41 | <itemizedlist>
|
---|
[69993f4] | 42 | <listitem><para>The output of programs translated into the native
|
---|
| 43 | language</para></listitem>
|
---|
| 44 | <listitem><para>Correct classification of characters into letters,
|
---|
[5ba3d1d] | 45 | digits and other classes. This is necessary for Bash to properly
|
---|
| 46 | accept non-ASCII characters in command lines in non-English
|
---|
[69993f4] | 47 | locales</para></listitem>
|
---|
| 48 | <listitem><para>The correct alphabetical sorting order for the
|
---|
| 49 | country</para></listitem>
|
---|
| 50 | <listitem><para>Appropriate default paper size</para></listitem>
|
---|
| 51 | <listitem><para>Correct formatting of monetary, time, and date
|
---|
| 52 | values</para></listitem>
|
---|
[181a690] | 53 | </itemizedlist>
|
---|
| 54 |
|
---|
[5ba3d1d] | 55 | <para>This script also sets the <emphasis>INPUTRC</emphasis>
|
---|
| 56 | environment variable that makes <application>Bash</application> and
|
---|
| 57 | <application>Readline</application> use the
|
---|
| 58 | <filename>/etc/inputrc</filename> file created earlier.</para>
|
---|
[181a690] | 59 |
|
---|
| 60 | <para>Replace <replaceable>[ll]</replaceable> below with the
|
---|
[5ba3d1d] | 61 | two-letter code for the desired language (e.g., <quote>en</quote>) and
|
---|
| 62 | <replaceable>[CC]</replaceable> with the two-letter code for the
|
---|
| 63 | appropriate country (e.g., <quote>GB</quote>). It may also be
|
---|
| 64 | necessary to specify (and this is actually the preferred form) the
|
---|
| 65 | character encoding (e.g. <quote>iso8859-1</quote>) after a dot (so
|
---|
| 66 | that the result is <quote>en_GB.iso8859-1</quote>). Issue the
|
---|
| 67 | following command for more information:</para>
|
---|
[b32e803] | 68 |
|
---|
| 69 | <screen><userinput>man 3 setlocale</userinput></screen>
|
---|
| 70 |
|
---|
[f67f5cf] | 71 | <para>The list of all locales supported by Glibc can be obtained by running
|
---|
[b32e803] | 72 | the following command:</para>
|
---|
| 73 |
|
---|
| 74 | <screen><userinput>locale -a</userinput></screen>
|
---|
| 75 |
|
---|
[5ba3d1d] | 76 | <para>Once the proper locale settings have been determined, create the
|
---|
[b32e803] | 77 | <filename>/etc/profile</filename> file:</para>
|
---|
[f67f5cf] | 78 |
|
---|
[b32e803] | 79 | <screen><userinput>cat > /etc/profile << "EOF"
|
---|
| 80 | # Begin /etc/profile
|
---|
| 81 |
|
---|
[f67f5cf] | 82 | export LC_ALL=<replaceable>[ll]</replaceable>_<replaceable>[CC]</replaceable>
|
---|
| 83 | export LANG=<replaceable>[ll]</replaceable>_<replaceable>[CC]</replaceable>
|
---|
[b32e803] | 84 | export INPUTRC=/etc/inputrc
|
---|
| 85 |
|
---|
| 86 | # End /etc/profile
|
---|
| 87 | EOF</userinput></screen>
|
---|
| 88 |
|
---|
[181a690] | 89 | <note><para>The <quote>C</quote> (default) and <quote>en_US</quote>
|
---|
[5ba3d1d] | 90 | (the recommended one for United States English users) locales are
|
---|
[181a690] | 91 | different.</para></note>
|
---|
| 92 |
|
---|
[69993f4] | 93 | <para>Setting the keyboard layout, screen font, and
|
---|
[5ba3d1d] | 94 | locale-related environment variables are the only internationalization
|
---|
| 95 | steps needed to support locales that use ordinary single-byte
|
---|
| 96 | encodings and left-to-right writing direction. More complex cases
|
---|
| 97 | (including UTF-8 based locales) require additional steps and
|
---|
| 98 | additional patches because many applications tend to not work properly
|
---|
| 99 | under such conditions. These steps and patches are not included in
|
---|
| 100 | the LFS book and such locales are not supported by LFS in any
|
---|
| 101 | way.</para>
|
---|
| 102 |
|
---|
[b32e803] | 103 | </sect1>
|
---|
[5ba3d1d] | 104 |
|
---|