source: chapter09/profile.xml@ 18d1f6f

multilib
Last change on this file since 18d1f6f was d8ec0ed, checked in by David Bryant <david@…>, 19 months ago

Clarified some things that seemed unclear.

Altered references to "a startup file" to "startup files".
Added detail to a reference to the bash info page. Tweaked
description of mafunctions caused by invalid locales. Clarified
descripton of extended ASCII characters. Every byte has the
high-order bit *set*; in extended ASCII, that bit is *on*.

  • Property mode set to 100644
File size: 8.0 KB
RevLine 
[b32e803]1<?xml version="1.0" encoding="ISO-8859-1"?>
[b06ca36]2<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
[b32e803]4 <!ENTITY % general-entities SYSTEM "../general.ent">
5 %general-entities;
6]>
[d781ffb]7
[afcfd74]8<sect1 id="ch-config-profile" revision="sysv">
[d781ffb]9 <?dbhtml filename="profile.html"?>
10
11 <title>The Bash Shell Startup Files</title>
12
[afcfd74]13 <indexterm zone="ch-config-profile">
[d781ffb]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
[d8ec0ed]19 create the environment to run in. Each file has a specific use and may affect
[d781ffb]20 login and interactive environments differently. The files in the <filename
[d8ec0ed]21 class="directory">/etc</filename> directory provide global settings. If
22 equivalent files exist in the home directory, they may override the global
[d781ffb]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
[d8ec0ed]33<para>For more information, see the <emphasis>Bash Startup Files</emphasis> and
34 <emphasis>Interactive Shells</emphasis> sections in the <emphasis>Bash
35 Features</emphasis> chapter of the Bash info pages (<command>info bash</command>).</para>
[d781ffb]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 other
51 classes. This is necessary for <command>bash</command> to properly accept
52 non-ASCII characters in command lines in non-English locales</para>
53 </listitem>
54 <listitem>
55 <para>The correct alphabetical sorting order for the country</para>
56 </listitem>
57 <listitem>
58 <para>Appropriate default paper size</para>
59 </listitem>
60 <listitem>
61 <para>Correct formatting of monetary, time, and date values</para>
62 </listitem>
63 </itemizedlist>
64
[0090db5]65 <para>Replace <replaceable>&lt;ll&gt;</replaceable> below with the two-letter code
[d781ffb]66 for the desired language (e.g., <quote>en</quote>) and
[0090db5]67 <replaceable>&lt;CC&gt;</replaceable> with the two-letter code for the appropriate
68 country (e.g., <quote>GB</quote>). <replaceable>&lt;charmap&gt;</replaceable> should
[fa21b3d]69 be replaced with the canonical charmap for your chosen locale. Optional
70 modifiers such as <quote>@euro</quote> may also be present.</para>
[d781ffb]71
72 <para>The list of all locales supported by Glibc can be obtained by running
73 the following command:</para>
[81fd230]74
[0ebe9fa4]75<screen role="nodump"><userinput>locale -a</userinput></screen>
[81fd230]76
[fa21b3d]77 <para>Charmaps can have a number of aliases, e.g., <quote>ISO-8859-1</quote>
[d781ffb]78 is also referred to as <quote>iso8859-1</quote> and <quote>iso88591</quote>.
[fa21b3d]79 Some applications cannot handle the various synonyms correctly (e.g., require
80 that <quote>UTF-8</quote> is written as <quote>UTF-8</quote>, not
81 <quote>utf8</quote>), so it is safest in most
82 cases to choose the canonical name for a particular locale. To determine
[0090db5]83 the canonical name, run the following command, where <replaceable>&lt;locale
84 name&gt;</replaceable> is the output given by <command>locale -a</command> for
[d781ffb]85 your preferred locale (<quote>en_GB.iso88591</quote> in our example).</para>
[768efb56]86
[0090db5]87<screen role="nodump"><userinput>LC_ALL=<replaceable>&lt;locale name&gt;</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>.
[d8ec0ed]95 It is important that the locale found using the heuristic above is tested before
96 it is added to the Bash startup files:</para>
[c45b780]97
[a85d4b9]98<screen role="nodump"><userinput>LC_ALL=&lt;locale name&gt; locale language
[0090db5]99LC_ALL=&lt;locale name&gt; locale charmap
100LC_ALL=&lt;locale name&gt; locale int_curr_symbol
101LC_ALL=&lt;locale name&gt; locale int_prefix</userinput></screen>
[c45b780]102
[3db5b78]103 <para>The above commands should print the language name, the character
104 encoding used by the locale, the local currency, and the prefix to dial
[d781ffb]105 before the telephone number in order to get into the country. If any of the
106 commands above fail with a message similar to the one shown below, this means
[c34b4fb]107 that your locale was either not installed in <xref linkend="ch-system-glibc"/>
[a3d0817]108 or is not supported by the default installation of Glibc.</para>
[c45b780]109
[ac1d807]110<screen><computeroutput>locale: Cannot set LC_* to default locale: No such file or directory</computeroutput></screen>
[c45b780]111
[d781ffb]112 <para>If this happens, you should either install the desired locale using the
113 <command>localedef</command> command, or consider choosing a different locale.
114 Further instructions assume that there are no such error messages from
115 Glibc.</para>
[c45b780]116
[fa21b3d]117 <!-- FIXME: the xlib example will became obsolete real soon -->
[a3d0817]118 <!--<para>Some packages beyond LFS may also lack support for your chosen locale. One
[d781ffb]119 example is the X library (part of the X Window System), which outputs the
[83f01733]120 following error message if the locale does not exactly match one of the character
121 map names in its internal files:</para>
[c45b780]122
[ac1d807]123<screen><computeroutput>Warning: locale not supported by Xlib, locale set to C</computeroutput></screen>
[c45b780]124
[83f01733]125 <para>In several cases Xlib expects that the character map will be listed in
126 uppercase notation with canonical dashes. For instance, "ISO-8859-1" rather
127 than "iso88591". It is also possible to find an appropriate specification by
128 removing the charmap part of the locale specification. This can be checked
129 by running the <command>locale charmap</command> command in both locales.
130 For example, one would have to change "de_DE.ISO-8859-15@euro" to
131 "de_DE@euro" in order to get this locale recognized by Xlib.</para>
[a3d0817]132-->
[d8ec0ed]133 <para>Other packages may also function incorrectly (but will not necessarily
[d781ffb]134 display any error messages) if the locale name does not meet their expectations.
[d8ec0ed]135 In such cases, investigating how other Linux distributions support your locale
[d781ffb]136 might provide some useful information.</para>
[768efb56]137
[d781ffb]138 <para>Once the proper locale settings have been determined, create the
139 <filename>/etc/profile</filename> file:</para>
[f67f5cf]140
[b32e803]141<screen><userinput>cat &gt; /etc/profile &lt;&lt; "EOF"
[d72e04a]142<literal># Begin /etc/profile
[b32e803]143
[e56d9dc]144export LANG=<replaceable>&lt;ll&gt;_&lt;CC&gt;.&lt;charmap&gt;&lt;@modifiers&gt;</replaceable>
[b32e803]145
[d72e04a]146# End /etc/profile</literal>
[b32e803]147EOF</userinput></screen>
148
[a3d0817]149 <para>The <quote>C</quote> (default) and <quote>en_US.utf8</quote> (the recommended
[fa21b3d]150 one for United States English users) locales are different. <quote>C</quote>
[d8ec0ed]151 uses the US-ASCII 7-bit character set, and treats bytes with the high-order bit set
152 <quote>on</quote> as invalid characters. That's why, e.g., the <command>ls</command> command
153 displays them as question marks in that locale. Also, an attempt to send
[fa21b3d]154 mail with such characters from Mutt or Pine results in non-RFC-conforming
155 messages being sent (the charset in the outgoing mail is indicated as <quote>unknown
[d8ec0ed]156 8-bit</quote>). So you can only use the <quote>C</quote> locale if you are sure
[fa21b3d]157 you will never need 8-bit characters.</para>
158
[b3eb525]159 <para>UTF-8 based locales are not supported well by some programs.
[d8ec0ed]160 Work is in progress to document and, if possible, fix such problems. See
[0ee07e5]161 <ulink url="&blfs-book;introduction/locale-issues.html"/>.</para>
[94aa6621]162
[b32e803]163</sect1>
Note: See TracBrowser for help on using the repository browser.