source: chapter07/profile.xml@ a85d4b9

10.0 10.0-rc1 10.1 10.1-rc1 11.0 11.0-rc1 11.0-rc2 11.0-rc3 11.1 11.1-rc1 11.2 11.2-rc1 11.3 11.3-rc1 12.0 12.0-rc1 12.1 12.1-rc1 6.3 6.4 6.5 6.6 6.7 6.8 7.0 7.1 7.2 7.3 7.4 7.5 7.5-systemd 7.6 7.6-systemd 7.7 7.7-systemd 7.8 7.8-systemd 7.9 7.9-systemd 8.0 8.1 8.2 8.3 8.4 9.0 9.1 arm bdubbs/gcc13 ml-11.0 multilib renodr/libudev-from-systemd s6-init trunk xry111/arm64 xry111/arm64-12.0 xry111/clfs-ng xry111/lfs-next xry111/loongarch xry111/loongarch-12.0 xry111/loongarch-12.1 xry111/mips64el xry111/pip3 xry111/rust-wip-20221008 xry111/update-glibc
Last change on this file since a85d4b9 was a85d4b9, checked in by Dan Nichilson <dnicholson@…>, 18 years ago

Removed the "locale country" command from the profile page since
it doesn't produce results in all locales.

git-svn-id: http://svn.linuxfromscratch.org/LFS/trunk/BOOK@7650 4aa44e1e-78dd-0310-a6d2-fbcd4c07a689

  • Property mode set to 100644
File size: 8.2 KB
Line 
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 <?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>&lt;ll&gt;</replaceable> below with the two-letter code
69 for the desired language (e.g., <quote>en</quote>) and
70 <replaceable>&lt;CC&gt;</replaceable> with the two-letter code for the appropriate
71 country (e.g., <quote>GB</quote>). <replaceable>&lt;charmap&gt;</replaceable> should
72 be replaced with the canonical charmap for your chosen locale. Optional
73 modifiers such as <quote>@euro</quote> may also be present.</para>
74
75 <para>The list of all locales supported by Glibc can be obtained by running
76 the following command:</para>
77
78<screen role="nodump"><userinput>locale -a</userinput></screen>
79
80 <para>Charmaps can have a number of aliases, e.g., <quote>ISO-8859-1</quote>
81 is also referred to as <quote>iso8859-1</quote> and <quote>iso88591</quote>.
82 Some applications cannot handle the various synonyms correctly (e.g., require
83 that <quote>UTF-8</quote> is written as <quote>UTF-8</quote>, not
84 <quote>utf8</quote>), so it is safest in most
85 cases to choose the canonical name for a particular locale. To determine
86 the canonical name, run the following command, where <replaceable>&lt;locale
87 name&gt;</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>&lt;locale name&gt;</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=&lt;locale name&gt; locale language
102LC_ALL=&lt;locale name&gt; locale charmap
103LC_ALL=&lt;locale name&gt; locale int_curr_symbol
104LC_ALL=&lt;locale name&gt; locale int_prefix</userinput></screen>
105
106 <para>The above commands should print the country and language names, the
107 character encoding used by the locale, the local currency and the prefix to dial
108 before the telephone number in order to get into the country. If any of the
109 commands above fail with a message similar to the one shown below, this means
110 that your locale was either not installed in Chapter 6 or is not supported by
111 the default installation of Glibc.</para>
112
113<screen><computeroutput>locale: Cannot set LC_* to default locale: No such file or directory</computeroutput></screen>
114
115 <para>If this happens, you should either install the desired locale using the
116 <command>localedef</command> command, or consider choosing a different locale.
117 Further instructions assume that there are no such error messages from
118 Glibc.</para>
119
120 <!-- FIXME: the xlib example will became obsolete real soon -->
121 <para>Some packages beyond LFS may also lack support for your chosen locale. One
122 example is the X library (part of the X Window System), which outputs the
123 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 the
128 locale specification, as long as that does not change the character map that
129 Glibc associates with the locale (this can be checked by running the
130 <command>locale charmap</command> command in both locales). For example, one
131 would have to change &quot;de_DE.ISO-8859-15@euro&quot; to
132 &quot;de_DE@euro&quot; 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 &gt; /etc/profile &lt;&lt; "EOF"
143<literal># Begin /etc/profile
144
145export LANG=<replaceable>&lt;ll&gt;</replaceable>_<replaceable>&lt;CC&gt;</replaceable>.<replaceable>&lt;charmap&gt;</replaceable><replaceable>&lt;@modifiers&gt;</replaceable>
146export INPUTRC=/etc/inputrc
147
148# End /etc/profile</literal>
149EOF</userinput></screen>
150
151 <para>The <quote>C</quote> (default) and <quote>en_US</quote> (the recommended
152 one for United States English users) locales are different. <quote>C</quote>
153 uses the US-ASCII 7-bit character set, and treats bytes with the high bit set
154 as invalid characters. That's why, e.g., the <command>ls</command> command
155 substitutes them with question marks in that locale. Also, an attempt to send
156 mail with such characters from Mutt or Pine results in non-RFC-conforming
157 messages being sent (the charset in the outgoing mail is indicated as <quote>unknown
158 8-bit</quote>). So you can use the <quote>C</quote> locale only if you are sure that
159 you will never need 8-bit characters.</para>
160
161 <para>UTF-8 based locales are not supported well by many programs. E.g., the
162 <command>watch</command> program displays only ASCII characters in UTF-8
163 locales and has no such restriction in traditional 8-bit locales like en_US.
164 Work is in progress to document and, if possible, fix such problems, see
165 <ulink url="&blfs-root;view/svn/introduction/locale-issues.html"/>.</para>
166
167</sect1>
Note: See TracBrowser for help on using the repository browser.