profile.xml 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. <sect1 id="ch-scripts-profile">
  8. <?dbhtml filename="profile.html"?>
  9. <title>The Bash Shell Startup Files</title>
  10. <indexterm zone="ch-scripts-profile">
  11. <primary sortas="e-/etc/profile">/etc/profile</primary>
  12. </indexterm>
  13. <para>The shell program <command>/bin/bash</command> (hereafter referred to
  14. as <quote>the shell</quote>) uses a collection of startup files to help
  15. create an environment to run in. Each file has a specific use and may affect
  16. login and interactive environments differently. The files in the <filename
  17. class="directory">/etc</filename> directory provide global settings. If an
  18. equivalent file exists in the home directory, it may override the global
  19. settings.</para>
  20. <para>An interactive login shell is started after a successful login, using
  21. <command>/bin/login</command>, by reading the <filename>/etc/passwd</filename>
  22. file. An interactive non-login shell is started at the command-line (e.g.,
  23. <prompt>[prompt]$</prompt><command>/bin/bash</command>). A non-interactive
  24. shell is usually present when a shell script is running. It is non-interactive
  25. because it is processing a script and not waiting for user input between
  26. commands.</para>
  27. <para>For more information, see <command>info bash</command> under the
  28. <emphasis>Bash Startup Files and Interactive Shells</emphasis> section.</para>
  29. <para>The files <filename>/etc/profile</filename> and
  30. <filename>~/.bash_profile</filename> are read when the shell is
  31. invoked as an interactive login shell.</para>
  32. <para>The base <filename>/etc/profile</filename> below sets some
  33. environment variables necessary for native language support. Setting
  34. them properly results in:</para>
  35. <itemizedlist>
  36. <listitem>
  37. <para>The output of programs translated into the native language</para>
  38. </listitem>
  39. <listitem>
  40. <para>Correct classification of characters into letters, digits and other
  41. classes. This is necessary for <command>bash</command> to properly accept
  42. non-ASCII characters in command lines in non-English locales</para>
  43. </listitem>
  44. <listitem>
  45. <para>The correct alphabetical sorting order for the country</para>
  46. </listitem>
  47. <listitem>
  48. <para>Appropriate default paper size</para>
  49. </listitem>
  50. <listitem>
  51. <para>Correct formatting of monetary, time, and date values</para>
  52. </listitem>
  53. </itemizedlist>
  54. <para>This script also sets the <envar>INPUTRC</envar> environment variable that
  55. makes Bash and Readline use the <filename>/etc/inputrc</filename> file created
  56. earlier.</para>
  57. <para>Replace <replaceable>[ll]</replaceable> below with the two-letter code
  58. for the desired language (e.g., <quote>en</quote>) and
  59. <replaceable>[CC]</replaceable> with the two-letter code for the appropriate
  60. country (e.g., <quote>GB</quote>). <replaceable>[charmap]</replaceable> should
  61. be replaced with the canonical charmap for your chosen locale. Optional
  62. modifiers such as <quote>@euro</quote> may also be present.</para>
  63. <para>The list of all locales supported by Glibc can be obtained by running
  64. the following command:</para>
  65. <screen role="nodump"><userinput>locale -a</userinput></screen>
  66. <para>Charmaps can have a number of aliases, e.g. <quote>ISO-8859-1</quote>
  67. is also referred to as <quote>iso8859-1</quote> and <quote>iso88591</quote>.
  68. Some applications cannot handle the various synonyms correctly (e.g. require
  69. that "UTF-8" is written as "UTF-8", not "utf8"), so it is safest in most
  70. cases to choose the canonical name for a particular locale. To determine
  71. the canonical name, run the following command, where <replaceable>[locale
  72. name]</replaceable> is the output given by <command>locale -a</command> for
  73. your preferred locale (<quote>en_GB.iso88591</quote> in our example).</para>
  74. <screen role="nodump"><userinput>LC_ALL=<replaceable>[locale name]</replaceable> locale charmap</userinput></screen>
  75. <para>For the <quote>en_GB.iso88591</quote> locale, the above command
  76. will print:</para>
  77. <screen><computeroutput>ISO-8859-1</computeroutput></screen>
  78. <para>This results in a final locale setting of <quote>en_GB.ISO-8859-1</quote>.
  79. It is important that the locale found using the heuristic above is tested prior
  80. to it being added to the Bash startup files:</para>
  81. <screen role="nodump"><userinput>LC_ALL=[locale name] locale country
  82. LC_ALL=[locale name] locale language
  83. LC_ALL=[locale name] locale charmap
  84. LC_ALL=[locale name] locale int_curr_symbol
  85. LC_ALL=[locale name] locale int_prefix</userinput></screen>
  86. <para>The above commands should print the country and language names, the
  87. character encoding used by the locale, the local currency and the prefix to dial
  88. before the telephone number in order to get into the country. If any of the
  89. commands above fail with a message similar to the one shown below, this means
  90. that your locale was either not installed in Chapter 6 or is not supported by
  91. the default installation of Glibc.</para>
  92. <screen><computeroutput>locale: Cannot set LC_* to default locale: No such file or directory</computeroutput></screen>
  93. <para>If this happens, you should either install the desired locale using the
  94. <command>localedef</command> command, or consider choosing a different locale.
  95. Further instructions assume that there are no such error messages from
  96. Glibc.</para>
  97. <!-- FIXME: the xlib example will became obsolete real soon -->
  98. <para>Some packages beyond LFS may also lack support for your chosen locale. One
  99. example is the X library (part of the X Window System), which outputs the
  100. following error message:</para>
  101. <screen><computeroutput>Warning: locale not supported by Xlib, locale set to C</computeroutput></screen>
  102. <para>Sometimes it is possible to fix this by removing the charmap part of the
  103. locale specification, as long as that does not change the character map that
  104. Glibc associates with the locale (this can be checked by running the
  105. <command>locale charmap</command> command in both locales). For example, one
  106. would have to change &quot;de_DE.ISO-8859-15@euro&quot; to
  107. &quot;de_DE@euro&quot; in order to get this locale recognized by Xlib.</para>
  108. <para>Other packages can also function incorrectly (but may not necessarily
  109. display any error messages) if the locale name does not meet their expectations.
  110. In those cases, investigating how other Linux distributions support your locale
  111. might provide some useful information.</para>
  112. <para>Once the proper locale settings have been determined, create the
  113. <filename>/etc/profile</filename> file:</para>
  114. <screen><userinput>cat &gt; /etc/profile &lt;&lt; "EOF"
  115. <literal># Begin /etc/profile
  116. export LANG=<replaceable>[ll]</replaceable>_<replaceable>[CC]</replaceable>.<replaceable>[charmap]</replaceable><replaceable>[@modifiers]</replaceable>
  117. export INPUTRC=/etc/inputrc
  118. # End /etc/profile</literal>
  119. EOF</userinput></screen>
  120. <para>The <quote>C</quote> (default) and <quote>en_US</quote> (the recommended
  121. one for United States English users) locales are different. <quote>C</quote>
  122. uses the US-ASCII 7-bit character set, and treats bytes with the high bit set
  123. as invalid characters. That's why, e.g., the <command>ls</command> command
  124. substitutes them with question marks in that locale. Also, an attempt to send
  125. mail with such characters from Mutt or Pine results in non-RFC-conforming
  126. messages being set (the charset in the outgoing mail is indicatsed as "unknown
  127. 8-bit"). So you can use the <quote>C</quote> locale only if you are sure that
  128. you will never need 8-bit characters.</para>
  129. <para>UTF-8 based locales are not supported well by many programs. E.g., the
  130. <command>watch</command> program displays only ASCII characters in UTF-8
  131. locales and has no such restriction in traditional 8-bit locales like en_US.
  132. Without patches and/or installing software beyond BLFS, in UTF-8 based locales
  133. you will not be able to do such basic tasks as printing plain-text files from
  134. the command line, recording Windows-readable CDs with filenames containing
  135. non-ASCII characters, viewing ID3v1 tags in MP3 files and so on. It is also
  136. impossible (without damaging non-ASCII characters) to connect using ssh from
  137. the system using a UTF-8 based locale to a host that still uses a traditional
  138. 8-bit locale, and vice versa. In short, use UTF-8 only if you are going to
  139. use KDE or GNOME and never open the terminal, or if you are going to tolerate
  140. bugs.</para>
  141. <!-- All abovementioned problems except "watch" have a known fix beyond BLFS -->
  142. <note>
  143. <para>Bug reports reproducible only in UTF-8 locales and for which there
  144. is no patch or other fix mentioned in the report, will be closed immediately,
  145. without investigation, with the "WONTFIX" resolution and a "don't use this
  146. program or revert to non-UTF-8 locale" comment. Patches that have ill
  147. effects in non-UTF-8 locales (other than replacement of translated program
  148. messages with English ones) will be rejected.</para>
  149. </note>
  150. </sect1>