source: chapter09/profile.xml@ a2434bd4

multilib
Last change on this file since a2434bd4 was d8ec0ed, checked in by David Bryant <david@…>, 17 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
Line 
1<?xml version="1.0" encoding="ISO-8859-1"?>
2<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
4 <!ENTITY % general-entities SYSTEM "../general.ent">
5 %general-entities;
6]>
7
8<sect1 id="ch-config-profile" revision="sysv">
9 <?dbhtml filename="profile.html"?>
10
11 <title>The Bash Shell Startup Files</title>
12
13 <indexterm zone="ch-config-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 the 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
22 equivalent files exist in the home directory, they 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 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>
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
65 <para>Replace <replaceable>&lt;ll&gt;</replaceable> below with the two-letter code
66 for the desired language (e.g., <quote>en</quote>) and
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
69 be replaced with the canonical charmap for your chosen locale. Optional
70 modifiers such as <quote>@euro</quote> may also be present.</para>
71
72 <para>The list of all locales supported by Glibc can be obtained by running
73 the following command:</para>
74
75<screen role="nodump"><userinput>locale -a</userinput></screen>
76
77 <para>Charmaps can have a number of aliases, e.g., <quote>ISO-8859-1</quote>
78 is also referred to as <quote>iso8859-1</quote> and <quote>iso88591</quote>.
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
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
85 your preferred locale (<quote>en_GB.iso88591</quote> in our example).</para>
86
87<screen role="nodump"><userinput>LC_ALL=<replaceable>&lt;locale name&gt;</replaceable> locale charmap</userinput></screen>
88
89 <para>For the <quote>en_GB.iso88591</quote> locale, the above command
90 will print:</para>
91
92<screen><computeroutput>ISO-8859-1</computeroutput></screen>
93
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 before
96 it is added to the Bash startup files:</para>
97
98<screen role="nodump"><userinput>LC_ALL=&lt;locale name&gt; locale language
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>
102
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
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
107 that your locale was either not installed in <xref linkend="ch-system-glibc"/>
108 or is not supported by the default installation of Glibc.</para>
109
110<screen><computeroutput>locale: Cannot set LC_* to default locale: No such file or directory</computeroutput></screen>
111
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>
116
117 <!-- FIXME: the xlib example will became obsolete real soon -->
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 if the locale does not exactly match one of the character
121 map names in its internal files:</para>
122
123<screen><computeroutput>Warning: locale not supported by Xlib, locale set to C</computeroutput></screen>
124
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>
132-->
133 <para>Other packages may also function incorrectly (but will not necessarily
134 display any error messages) if the locale name does not meet their expectations.
135 In such cases, investigating how other Linux distributions support your locale
136 might provide some useful information.</para>
137
138 <para>Once the proper locale settings have been determined, create the
139 <filename>/etc/profile</filename> file:</para>
140
141<screen><userinput>cat &gt; /etc/profile &lt;&lt; "EOF"
142<literal># Begin /etc/profile
143
144export LANG=<replaceable>&lt;ll&gt;_&lt;CC&gt;.&lt;charmap&gt;&lt;@modifiers&gt;</replaceable>
145
146# End /etc/profile</literal>
147EOF</userinput></screen>
148
149 <para>The <quote>C</quote> (default) and <quote>en_US.utf8</quote> (the recommended
150 one for United States English users) locales are different. <quote>C</quote>
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
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
156 8-bit</quote>). So you can only use the <quote>C</quote> locale if you are sure
157 you will never need 8-bit characters.</para>
158
159 <para>UTF-8 based locales are not supported well by some programs.
160 Work is in progress to document and, if possible, fix such problems. See
161 <ulink url="&blfs-book;introduction/locale-issues.html"/>.</para>
162
163</sect1>
Note: See TracBrowser for help on using the repository browser.