[b32e803] | 1 | <?xml version="1.0" encoding="ISO-8859-1"?>
|
---|
[1770019] | 2 | <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
|
---|
[b32e803] | 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 |
|
---|
[81fd230] | 10 | <indexterm zone="ch-scripts-profile"><primary sortas="e-/etc/profile">/etc/profile</primary></indexterm>
|
---|
[f67f5cf] | 11 |
|
---|
[81fd230] | 12 | <para>The shell program <command>/bin/bash</command> (hereafter
|
---|
| 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
|
---|
[4ccba55] | 15 | specific use and may affect login and interactive environments
|
---|
[81fd230] | 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 |
|
---|
[cce9fef] | 30 | <para>For more information, see <command>info bash</command> under the
|
---|
| 31 | <emphasis>Bash Startup Files and Interactive Shells</emphasis> section.</para>
|
---|
[81fd230] | 32 |
|
---|
| 33 | <para>The files <filename>/etc/profile</filename> and
|
---|
| 34 | <filename>~/.bash_profile</filename> are read when the shell is
|
---|
| 35 | invoked as an interactive login shell.</para>
|
---|
| 36 |
|
---|
[cce9fef] | 37 | <para>The base <filename>/etc/profile</filename> below sets some
|
---|
[81fd230] | 38 | environment variables necessary for native language support. Setting
|
---|
| 39 | them properly results in:</para>
|
---|
| 40 |
|
---|
| 41 | <itemizedlist>
|
---|
| 42 | <listitem><para>The output of programs translated into the native
|
---|
| 43 | language</para></listitem>
|
---|
| 44 | <listitem><para>Correct classification of characters into letters,
|
---|
| 45 | digits and other classes. This is necessary for Bash to properly
|
---|
| 46 | accept non-ASCII characters in command lines in non-English
|
---|
| 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>
|
---|
| 53 | </itemizedlist>
|
---|
| 54 |
|
---|
[c5ec23b] | 55 | <para>This script also sets the <envar>INPUTRC</envar> environment variable that
|
---|
| 56 | makes Bash and Readline use the <filename>/etc/inputrc</filename> file created
|
---|
| 57 | earlier.</para>
|
---|
[81fd230] | 58 |
|
---|
| 59 | <para>Replace <replaceable>[ll]</replaceable> below with the
|
---|
| 60 | two-letter code for the desired language (e.g., <quote>en</quote>) and
|
---|
| 61 | <replaceable>[CC]</replaceable> with the two-letter code for the
|
---|
[411697d] | 62 | appropriate country (e.g., <quote>GB</quote>).
|
---|
| 63 | <replaceable>[charmap]</replaceable> should be replaced with the
|
---|
| 64 | canonical charmap for your chosen locale.</para>
|
---|
[81fd230] | 65 |
|
---|
| 66 | <para>The list of all locales supported by Glibc can be obtained by running
|
---|
| 67 | the following command:</para>
|
---|
| 68 |
|
---|
| 69 | <screen><userinput>locale -a</userinput></screen>
|
---|
| 70 |
|
---|
[411697d] | 71 | <para>Locales can have a number of synonyms, e.g. <quote>ISO-8859-1</quote> is
|
---|
| 72 | also referred to as <quote>iso8859-1</quote> and <quote>iso88591</quote>.
|
---|
| 73 | Some applications cannot handle the various synonyms correctly, so it is safest
|
---|
| 74 | to choose the canonical name for a particular locale. To determine the
|
---|
| 75 | canonical name, run the following command, where
|
---|
| 76 | <replaceable>[locale name]</replaceable> is the output given by
|
---|
| 77 | <command>locale -a</command> for your preferred locale
|
---|
| 78 | (<quote>en_GB.iso88591</quote> in our example).</para>
|
---|
| 79 |
|
---|
| 80 | <screen><userinput>LC_ALL=<replaceable>[locale name]</replaceable> locale charmap</userinput></screen>
|
---|
| 81 |
|
---|
| 82 | <para>For the <quote>en_GB.iso88591</quote> locale, the above command
|
---|
| 83 | will print:</para>
|
---|
| 84 |
|
---|
| 85 | <screen>ISO-8859-1</screen>
|
---|
| 86 |
|
---|
| 87 | <para>This results in in a final locale setting of <quote>en_GB.ISO-8859-1</quote>.</para>
|
---|
| 88 |
|
---|
[81fd230] | 89 | <para>Once the proper locale settings have been determined, create the
|
---|
| 90 | <filename>/etc/profile</filename> file:</para>
|
---|
[f67f5cf] | 91 |
|
---|
[b32e803] | 92 | <screen><userinput>cat > /etc/profile << "EOF"
|
---|
[d72e04a] | 93 | <literal># Begin /etc/profile
|
---|
[b32e803] | 94 |
|
---|
[411697d] | 95 | export LANG=<replaceable>[ll]</replaceable>_<replaceable>[CC]</replaceable>.<replaceable>[charmap]</replaceable>
|
---|
[b32e803] | 96 | export INPUTRC=/etc/inputrc
|
---|
| 97 |
|
---|
[d72e04a] | 98 | # End /etc/profile</literal>
|
---|
[b32e803] | 99 | EOF</userinput></screen>
|
---|
| 100 |
|
---|
[81fd230] | 101 | <note><para>The <quote>C</quote> (default) and <quote>en_US</quote>
|
---|
| 102 | (the recommended one for United States English users) locales are
|
---|
| 103 | different.</para></note>
|
---|
| 104 |
|
---|
| 105 | <para>Setting the keyboard layout, screen font, and
|
---|
| 106 | locale-related environment variables are the only internationalization
|
---|
| 107 | steps needed to support locales that use ordinary single-byte
|
---|
| 108 | encodings and left-to-right writing direction. More complex cases
|
---|
| 109 | (including UTF-8 based locales) require additional steps and
|
---|
| 110 | additional patches because many applications tend to not work properly
|
---|
| 111 | under such conditions. These steps and patches are not included in
|
---|
[cce9fef] | 112 | the LFS book and such locales are not yet supported by LFS.</para>
|
---|
[81fd230] | 113 |
|
---|
[b32e803] | 114 | </sect1>
|
---|
[81fd230] | 115 |
|
---|