[b32e803] | 1 | <?xml version="1.0" encoding="ISO-8859-1"?>
|
---|
[d781ffb] | 2 | <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
|
---|
| 3 | "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
|
---|
[b32e803] | 4 | <!ENTITY % general-entities SYSTEM "../general.ent">
|
---|
| 5 | %general-entities;
|
---|
| 6 | ]>
|
---|
[d781ffb] | 7 |
|
---|
[b32e803] | 8 | <sect1 id="ch-scripts-profile">
|
---|
[d781ffb] | 9 | <?dbhtml filename="profile.html"?>
|
---|
| 10 |
|
---|
| 11 | <title>The Bash Shell Startup Files</title>
|
---|
| 12 |
|
---|
| 13 | <indexterm zone="ch-scripts-profile">
|
---|
| 14 | <primary sortas="e-/etc/profile">/etc/profile</primary>
|
---|
| 15 | </indexterm>
|
---|
| 16 |
|
---|
| 17 | <para>The shell program <command>/bin/bash</command> (hereafter referred to
|
---|
| 18 | as <quote>the shell</quote>) uses a collection of startup files to help
|
---|
| 19 | create an environment to run in. Each file has a specific use and may affect
|
---|
| 20 | login and interactive environments differently. The files in the <filename
|
---|
| 21 | class="directory">/etc</filename> directory provide global settings. If an
|
---|
| 22 | equivalent file exists in the home directory, it may override the global
|
---|
| 23 | settings.</para>
|
---|
| 24 |
|
---|
| 25 | <para>An interactive login shell is started after a successful login, using
|
---|
| 26 | <command>/bin/login</command>, by reading the <filename>/etc/passwd</filename>
|
---|
| 27 | file. An interactive non-login shell is started at the command-line (e.g.,
|
---|
| 28 | <prompt>[prompt]$</prompt><command>/bin/bash</command>). A non-interactive
|
---|
| 29 | shell is usually present when a shell script is running. It is non-interactive
|
---|
| 30 | because it is processing a script and not waiting for user input between
|
---|
| 31 | commands.</para>
|
---|
| 32 |
|
---|
| 33 | <para>For more information, see <command>info bash</command> under the
|
---|
| 34 | <emphasis>Bash Startup Files and Interactive Shells</emphasis> section.</para>
|
---|
| 35 |
|
---|
| 36 | <para>The files <filename>/etc/profile</filename> and
|
---|
| 37 | <filename>~/.bash_profile</filename> are read when the shell is
|
---|
| 38 | invoked as an interactive login shell.</para>
|
---|
| 39 |
|
---|
| 40 | <para>The base <filename>/etc/profile</filename> below sets some
|
---|
| 41 | environment variables necessary for native language support. Setting
|
---|
| 42 | them properly results in:</para>
|
---|
| 43 |
|
---|
| 44 | <itemizedlist>
|
---|
| 45 | <listitem>
|
---|
| 46 | <para>The output of programs translated into the native language</para>
|
---|
| 47 | </listitem>
|
---|
| 48 | <listitem>
|
---|
| 49 | <para>Correct classification of characters into letters, digits and other
|
---|
| 50 | classes. This is necessary for <command>bash</command> to properly accept
|
---|
| 51 | non-ASCII characters in command lines in non-English locales</para>
|
---|
| 52 | </listitem>
|
---|
| 53 | <listitem>
|
---|
| 54 | <para>The correct alphabetical sorting order for the country</para>
|
---|
| 55 | </listitem>
|
---|
| 56 | <listitem>
|
---|
| 57 | <para>Appropriate default paper size</para>
|
---|
| 58 | </listitem>
|
---|
| 59 | <listitem>
|
---|
| 60 | <para>Correct formatting of monetary, time, and date values</para>
|
---|
| 61 | </listitem>
|
---|
| 62 | </itemizedlist>
|
---|
| 63 |
|
---|
| 64 | <para>This script also sets the <envar>INPUTRC</envar> environment variable that
|
---|
| 65 | makes Bash and Readline use the <filename>/etc/inputrc</filename> file created
|
---|
| 66 | earlier.</para>
|
---|
| 67 |
|
---|
| 68 | <para>Replace <replaceable>[ll]</replaceable> below with the two-letter code
|
---|
| 69 | for the desired language (e.g., <quote>en</quote>) and
|
---|
| 70 | <replaceable>[CC]</replaceable> with the two-letter code for the appropriate
|
---|
| 71 | country (e.g., <quote>GB</quote>). <replaceable>[charmap]</replaceable> should
|
---|
| 72 | be replaced with the canonical charmap for your chosen locale.</para>
|
---|
| 73 |
|
---|
| 74 | <para>The list of all locales supported by Glibc can be obtained by running
|
---|
| 75 | the following command:</para>
|
---|
[81fd230] | 76 |
|
---|
[0ebe9fa4] | 77 | <screen role="nodump"><userinput>locale -a</userinput></screen>
|
---|
[81fd230] | 78 |
|
---|
[d781ffb] | 79 | <para>Locales can have a number of synonyms, e.g. <quote>ISO-8859-1</quote>
|
---|
| 80 | is also referred to as <quote>iso8859-1</quote> and <quote>iso88591</quote>.
|
---|
| 81 | Some applications cannot handle the various synonyms correctly, so it is
|
---|
| 82 | safest to choose the canonical name for a particular locale. To determine
|
---|
| 83 | the canonical name, run the following command, where <replaceable>[locale
|
---|
| 84 | name]</replaceable> is the output given by <command>locale -a</command> for
|
---|
| 85 | your preferred locale (<quote>en_GB.iso88591</quote> in our example).</para>
|
---|
[768efb56] | 86 |
|
---|
[0ebe9fa4] | 87 | <screen role="nodump"><userinput>LC_ALL=<replaceable>[locale name]</replaceable> locale charmap</userinput></screen>
|
---|
[768efb56] | 88 |
|
---|
[d781ffb] | 89 | <para>For the <quote>en_GB.iso88591</quote> locale, the above command
|
---|
| 90 | will print:</para>
|
---|
[768efb56] | 91 |
|
---|
[d781ffb] | 92 | <screen><computeroutput>ISO-8859-1</computeroutput></screen>
|
---|
[768efb56] | 93 |
|
---|
[d781ffb] | 94 | <para>This results in a final locale setting of <quote>en_GB.ISO-8859-1</quote>.
|
---|
| 95 | It is important that the locale found using the heuristic above is tested prior
|
---|
| 96 | to it being added to the Bash startup files:</para>
|
---|
[c45b780] | 97 |
|
---|
[82aac74] | 98 | <screen role="nodump"><userinput>LC_ALL=[locale name] locale country
|
---|
[c45b780] | 99 | LC_ALL=[locale name] locale language
|
---|
| 100 | LC_ALL=[locale name] locale charmap
|
---|
| 101 | LC_ALL=[locale name] locale int_curr_symbol
|
---|
| 102 | LC_ALL=[locale name] locale int_prefix</userinput></screen>
|
---|
| 103 |
|
---|
[d781ffb] | 104 | <para>The above commands should print the country and language names, the
|
---|
| 105 | character encoding used by the locale, the local currency and the prefix to dial
|
---|
| 106 | before the telephone number in order to get into the country. If any of the
|
---|
| 107 | commands above fail with a message similar to the one shown below, this means
|
---|
| 108 | that your locale was either not installed in Chapter 6 or is not supported by
|
---|
| 109 | the default installation of Glibc.</para>
|
---|
[c45b780] | 110 |
|
---|
[ac1d807] | 111 | <screen><computeroutput>locale: Cannot set LC_* to default locale: No such file or directory</computeroutput></screen>
|
---|
[c45b780] | 112 |
|
---|
[d781ffb] | 113 | <para>If this happens, you should either install the desired locale using the
|
---|
| 114 | <command>localedef</command> command, or consider choosing a different locale.
|
---|
| 115 | Further instructions assume that there are no such error messages from
|
---|
| 116 | Glibc.</para>
|
---|
[c45b780] | 117 |
|
---|
[d781ffb] | 118 | <para>Some packages beyond LFS may also lack support for your chosen locale. One
|
---|
| 119 | example is the X library (part of the X Window System), which outputs the
|
---|
| 120 | following error message:</para>
|
---|
[c45b780] | 121 |
|
---|
[ac1d807] | 122 | <screen><computeroutput>Warning: locale not supported by Xlib, locale set to C</computeroutput></screen>
|
---|
[c45b780] | 123 |
|
---|
[d781ffb] | 124 | <para>Sometimes it is possible to fix this by removing the charmap part of the
|
---|
| 125 | locale specification, as long as that does not change the character map that
|
---|
| 126 | Glibc associates with the locale (this can be checked by running the
|
---|
| 127 | <command>locale charmap</command> command in both locales). For example, one
|
---|
| 128 | would have to change "de_DE.ISO-8859-15@euro" to
|
---|
| 129 | "de_DE@euro" in order to get this locale recognized by Xlib.</para>
|
---|
[c45b780] | 130 |
|
---|
[d781ffb] | 131 | <para>Other packages can also function incorrectly (but may not necessarily
|
---|
| 132 | display any error messages) if the locale name does not meet their expectations.
|
---|
| 133 | In those cases, investigating how other Linux distributions support your locale
|
---|
| 134 | might provide some useful information.</para>
|
---|
[768efb56] | 135 |
|
---|
[d781ffb] | 136 | <para>Once the proper locale settings have been determined, create the
|
---|
| 137 | <filename>/etc/profile</filename> file:</para>
|
---|
[f67f5cf] | 138 |
|
---|
[b32e803] | 139 | <screen><userinput>cat > /etc/profile << "EOF"
|
---|
[d72e04a] | 140 | <literal># Begin /etc/profile
|
---|
[b32e803] | 141 |
|
---|
[768efb56] | 142 | export LANG=<replaceable>[ll]</replaceable>_<replaceable>[CC]</replaceable>.<replaceable>[charmap]</replaceable>
|
---|
[b32e803] | 143 | export INPUTRC=/etc/inputrc
|
---|
| 144 |
|
---|
[d72e04a] | 145 | # End /etc/profile</literal>
|
---|
[b32e803] | 146 | EOF</userinput></screen>
|
---|
| 147 |
|
---|
[d781ffb] | 148 | <note>
|
---|
| 149 | <para>The <quote>C</quote> (default) and <quote>en_US</quote> (the
|
---|
| 150 | recommended one for United States English users) locales are different.</para>
|
---|
| 151 | </note>
|
---|
[81fd230] | 152 |
|
---|
[d781ffb] | 153 | <para>Setting the keyboard layout, screen font, and locale-related environment
|
---|
| 154 | variables are the only internationalization steps needed to support locales
|
---|
| 155 | that use ordinary single-byte encodings and left-to-right writing direction.
|
---|
| 156 | More complex cases (including UTF-8 based locales) require additional steps
|
---|
| 157 | and additional patches because many applications tend to not work properly
|
---|
| 158 | under such conditions. These steps and patches are not included in the LFS
|
---|
| 159 | book and such locales are not yet supported by LFS.</para>
|
---|
[81fd230] | 160 |
|
---|
[b32e803] | 161 | </sect1>
|
---|