profile.xml 7.2 KB

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