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