1
0

profile.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <?xml version="1.0" encoding="UTF-8"?>
  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. <sect1 id="ch-scripts-profile" revision="sysv">
  8. <?dbhtml filename="profile.html"?>
  9. <title>Bash Shell 启动文件</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>Shell 程序 <command>/bin/bash</command> (之后简称 shell)
  21. 使用一组启动文件,以帮助创建运行环境。每个文件都有专门的用途,
  22. 可能以不同方式影响登录和交互环境。
  23. <filename class="directory">/etc</filename> 目录中的文件提供全局设定,
  24. 如果在用户主目录中有对应的文件存在,它可能覆盖全局设定。</para>
  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. <para>在使用 <command>/bin/login</command> 成功登录后,
  33. 它读取 <filename>/etc/passwd</filename> 中的 shell 命令行,
  34. 启动一个交互式登录 shell。通过命令行(如
  35. <prompt>[prompt]$</prompt><command>/bin/bash</command>)
  36. 可以启动一个交互式非登录 shell。非交互 shell 通常在 shell 脚本运行时存在,
  37. 它处理脚本,在执行命令时不需要等待用户输入,因此是非交互的。</para>
  38. <!--para>For more information, see <command>info bash</command> under the
  39. <emphasis>Bash Startup Files and Interactive Shells</emphasis> section.</para-->
  40. <para>阅读 <command>info bash</command> 中
  41. <emphasis>Bash Startup Files and Interactive Shells</emphasis> 一节,
  42. 了解更多信息。</para>
  43. <!--para>The files <filename>/etc/profile</filename> and
  44. <filename>~/.bash_profile</filename> are read when the shell is
  45. invoked as an interactive login shell.</para-->
  46. <para>文件 <filename>/etc/profile</filename> 和
  47. <filename>~/.bash_profile</filename> 在 shell 作为交互登录 shell
  48. 时被读取。</para>
  49. <!--para>The base <filename>/etc/profile</filename> below sets some
  50. environment variables necessary for native language support. Setting
  51. them properly results in:</para-->
  52. <para>下面给出的基本 <filename>/etc/profile</filename>
  53. 设定本地语言支持需要的环境变量,正确设定它们有以下好处:</para>
  54. <itemizedlist>
  55. <listitem>
  56. <para>程序输出被翻译成本地语言</para>
  57. </listitem>
  58. <listitem>
  59. <para>字符被正确分类为字母、数字和其他类别,
  60. 这对于使 <command>bash</command> 正确接受命令行中的非 ASCII
  61. 本地字符来说是必要的</para>
  62. </listitem>
  63. <listitem>
  64. <para>根据所在地区惯例排序字母</para>
  65. </listitem>
  66. <listitem>
  67. <para>适用于所在地区的默认纸张尺寸</para>
  68. </listitem>
  69. <listitem>
  70. <para>正确格式化货币、时间和日期值</para>
  71. </listitem>
  72. </itemizedlist>
  73. <note><title>译注</title>
  74. <para>译者强烈反对在 <filename>/etc/profile</filename>
  75. 中指定中文 locale。由于字符终端的局限性,它根本无法显示中文字符。
  76. 使用中文 locale 将导致许多程序输出中文消息,
  77. 结果在字符终端中都显示为问号。建议在
  78. <filename>/etc/locale.conf</filename> 中指定英文 locale ,
  79. 在 BLFS 中安装了图形环境后再将
  80. <literal>LANG=zh_CN.UTF-8</literal> 写入
  81. <filename>.xprofile</filename> 等图形界面配置文件,
  82. 这样即可在字符终端中使用英文 locale ,而在图形界面中使用中文。
  83. </para>
  84. </note>
  85. <para>将下面的 <replaceable>&lt;ll&gt;</replaceable>
  86. 替换为所需语言的双字符代号(例如 <quote>en</quote>),
  87. <replaceable>&lt;CC&gt;</replaceable> 替换为国家或地区的双字符代号
  88. (例如 <quote>GB</quote>),
  89. <replaceable>&lt;charmap&gt;</replaceable> 替换为您选定的 locale
  90. 的标准字符映射。另外,还可以加入 <quote>@euro</quote>
  91. 之类的可选修饰符。</para>
  92. <para>Glibc 支持的所有 locale 可以用以下命令列出:</para>
  93. <screen role="nodump"><userinput>locale -a</userinput></screen>
  94. <para>字符映射可能有多个别名,例如 <quote>ISO-8859-1</quote>
  95. 也可以称为 <quote>iso8859-1</quote> 和 <quote>iso88591</quote>。
  96. 某些程序不能正确处理一些别名(例如,只识别 <quote>UTF-8</quote>,
  97. 不能识别 <quote>utf8</quote>),因此在多数情况下,为了保险起见,
  98. 最好使用 locale 的规范名称。为了确定规范名称,执行以下命令,
  99. 将 <replaceable>&lt;locale name&gt;</replaceable> 替换成
  100. <command>locale -a</command> 对于您希望的 locale 的输出
  101. (以 <quote>en_GB.iso88591</quote> 为例)。</para>
  102. <screen role="nodump"><userinput>LC_ALL=<replaceable>&lt;locale name&gt;</replaceable> locale charmap</userinput></screen>
  103. <para>对于 <quote>en_GB.iso88591</quote> locale,以上命令输出:</para>
  104. <screen><computeroutput>ISO-8859-1</computeroutput></screen>
  105. <para>这样就最终确定 locale 应设置为 <quote>en_GB.ISO-8859-1</quote>。
  106. 在将以上启发方法获得的 locale 添加到 Bash 启动文件之前,
  107. 一定要进行下列测试:</para>
  108. <screen role="nodump"><userinput>LC_ALL=&lt;locale name&gt; locale language
  109. LC_ALL=&lt;locale name&gt; locale charmap
  110. LC_ALL=&lt;locale name&gt; locale int_curr_symbol
  111. LC_ALL=&lt;locale name&gt; locale int_prefix</userinput></screen>
  112. <!--para>The above commands should print the language name, the character
  113. encoding used by the locale, the local currency, and the prefix to dial
  114. before the telephone number in order to get into the country. If any of the
  115. commands above fail with a message similar to the one shown below, this means
  116. that your locale was either not installed in Chapter&nbsp;6 or is not supported by
  117. the default installation of Glibc.</para-->
  118. <para>以上命令应该输出语言名称、选定 locale 使用的字符编码、
  119. 本地货币符号以及所在国家或地区的国际电话区号。
  120. 如果以上某个命令失败并输出类似下面这样的消息,
  121. 意味着您的 locale 在第 6 章中没有安装,或者不被 Glibc 的默认安装支持。
  122. </para>
  123. <screen><computeroutput>locale: Cannot set LC_* to default locale: No such file or directory</computeroutput></screen>
  124. <!--para>If this happens, you should either install the desired locale using the
  125. <command>localedef</command> command, or consider choosing a different locale.
  126. Further instructions assume that there are no such error messages from
  127. Glibc.</para-->
  128. <para>如果出现了这种消息,您应该用 <command>localedef</command>
  129. 命令安装所需的 locale ,或重新选择一个不同的 locale 。
  130. 后文假设 Glibc 没有输出类似错误消息。</para>
  131. <!-- FIXME: the xlib example will became obsolete real soon -->
  132. <!--para>Some packages beyond LFS may also lack support for your chosen locale. One
  133. example is the X library (part of the X Window System), which outputs the
  134. following error message if the locale does not exactly match one of the character
  135. map names in its internal files:</para-->
  136. <para>某些 LFS 以外的软件包可能缺乏对您选择的 locale 的支持,
  137. 例如 X 库(X 窗口系统的一部分),它在您的 locale
  138. 与它内部文件中的字符映射表名不完全匹配时,会输出以下错误消息:</para>
  139. <screen><computeroutput>Warning: locale not supported by Xlib, locale set to C</computeroutput></screen>
  140. <!--para>In several cases Xlib expects that the character map will be listed in
  141. uppercase notation with canonical dashes. For instance, "ISO-8859-1" rather
  142. than "iso88591". It is also possible to find an appropriate specification by
  143. removing the charmap part of the locale specification. This can be checked
  144. by running the <command>locale charmap</command> command in both locales.
  145. For example, one would have to change "de_DE.ISO-8859-15@euro" to
  146. "de_DE@euro" in order to get this locale recognized by Xlib.</para-->
  147. <para>某些情况下 Xlib 期望字符映射以带有规范连字符的大写形式给出,
  148. 例如应该使用 <quote>ISO-8859-1</quote> 而不是
  149. <quote>iso88591</quote>。
  150. 有时也可以通过去除 locale 规范中的字符映射部分找到合适的规范,
  151. 可以通过运行 <command>locale charmap</command> 确认。
  152. 例如,您需要将 <quote>de_DE.ISO-8859-15@euro</quote>
  153. 替换成 <quote>de_DE@euro</quote>,以获得 Xlib 能够识别的 locale。
  154. </para>
  155. <!--para>Other packages can also function incorrectly (but may not necessarily
  156. display any error messages) if the locale name does not meet their expectations.
  157. In those cases, investigating how other Linux distributions support your locale
  158. might provide some useful information.</para-->
  159. <para>其他软件包在 locale 名不符合它们的期望时可能工作不正常
  160. (但未必输出错误消息)。在这种情况下,探索一下其他 Linux
  161. 发行版是如何支持您的 locale 的,可以得到一些有用的信息。</para>
  162. <para>在确定了正确的 locale 设置后,创建
  163. <filename>/etc/profile</filename> 文件:</para>
  164. <screen><userinput>cat &gt; /etc/profile &lt;&lt; "EOF"
  165. <literal># Begin /etc/profile
  166. export LANG=<replaceable>&lt;ll&gt;_&lt;CC&gt;.&lt;charmap&gt;&lt;@modifiers&gt;</replaceable>
  167. # End /etc/profile</literal>
  168. EOF</userinput></screen>
  169. <!--para>The <quote>C</quote> (default) and <quote>en_US</quote> (the recommended
  170. one for United States English users) locales are different. <quote>C</quote>
  171. uses the US-ASCII 7-bit character set, and treats bytes with the high bit set
  172. as invalid characters. That's why, e.g., the <command>ls</command> command
  173. substitutes them with question marks in that locale. Also, an attempt to send
  174. mail with such characters from Mutt or Pine results in non-RFC-conforming
  175. messages being sent (the charset in the outgoing mail is indicated as <quote>unknown
  176. 8-bit</quote>). So you can use the <quote>C</quote> locale only if you are sure that
  177. you will never need 8-bit characters.</para-->
  178. <para><quote>C</quote> (默认 locale)和 <quote>en_US</quote>
  179. (推荐美式英语用户使用的 locale)是不同的。
  180. <quote>C</quote> locale 使用 US-ASCII 7 位字符集,并且将最高位为 1
  181. 的字节视为无效字符。因此,<command>ls</command>
  182. 等命令会将它们替换为问号。另外,如果试图用 Mutt 或 Pine
  183. 发送包含这些字符的邮件,会发出不符合 RFC 标准的消息
  184. (发出邮件的字符集会被标为 <quote>未知 8 位</quote>)。
  185. 因此,您只能在确信自己永远不会使用 8 位字符时才能使用
  186. <quote>C</quote> locale。</para>
  187. <para>许多程序不能很好地支持基于 UTF-8 的 locale,
  188. 我们正在努力记录并(如果可能的话)修复它们,参阅
  189. <ulink url="&blfs-book;introduction/locale-issues.html"/>。</para>
  190. </sect1>