📄 profile.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=gb2312" />
<title>
7.9. The Bash Shell Startup Files
</title>
<link rel="stylesheet" href="../stylesheets/lfs.css" type="text/css" />
<meta name="generator" content="DocBook XSL Stylesheets V1.68.1" />
<link rel="stylesheet" href="../stylesheets/lfs-print.css" type="text/css" media="print" />
</head>
<body id="lfs" class="6.1">
<div class="navheader">
<div class="headertitles">
<h4>
Linux From Scratch - Version 6.1
</h4>
<h3>
Chapter 7. 配置系统启动脚本(Bootscripts)
</h3>
</div>
<ul class="headerlinks">
<li class="prev">
<a accesskey="p" href="inputrc.html" title="Creating the /etc/inputrc File">后退</a>
<p>
Creating the /etc/inputrc File
</p>
</li>
<li class="next">
<a accesskey="n" href="hostname.html" title="Configuring the localnet Script">前进</a>
<p>
Configuring the localnet Script
</p>
</li>
<li class="up">
<a accesskey="u" href="chapter07.html" title="Chapter 7. 配置系统启动脚本(Bootscripts)">上一级</a>.
</li>
<li class="home">
<a accesskey="h" href="../index.html" title="Linux From Scratch - Version 6.1">回首页</a>
</li>
</ul>
</div>
<div class="sect1" lang="zh_cn" xml:lang="zh_cn">
<div class="titlepage">
<h1 class="sect1">
7.9. Bash Shell 的启动文件</h1>
</div>
<p><span><strong class="command">/bin/bash</strong></span> 程序(后面我们称之为“shell”)使用一些启动文件来协助创建一个运行环境,其中每个文件都有特定的用途,对登录和交互环境的影响也各不相同。 <tt class="filename">/etc</tt>
目录下的文件提供全局设置,如果用户主目录下存在同名文件,它将覆盖全局设置。</p>
<p>
使用
<span><strong class="command">/bin/login</strong></span> 读取 <tt class="filename">/etc/passwd</tt> 文件成功登录后,启动了一个交互登录 shell。用命令行可以启动一个交互非登录 shell(例如<tt class="prompt">[prompt]$</tt><span><strong class="command">/bin/bash</strong></span>)。非交互 shell 通常出现在 shell 脚本运行的时候,之所以称为非交互的,因为它正在运行一个脚本,而且命令与命令之间并不等待用户的输入。</p>
<p>
要获得更多信息,请运行 <span><strong class="command">info
bash</strong></span> 并参考 <span class="emphasis"><em>Bash
Startup Files and Interactive Shells</em></span> 小节。</p>
<p>
当以交互登录方式运行 shell 的时候,会读取 <tt class="filename">/etc/profile</tt> 和 <tt class="filename">~/.bash_profile</tt> 文件。</p>
<p>
下面是一个基本的 <tt class="filename">/etc/profile</tt> 文件,设置了本地语言支持所必需的环境变量,适当设置这些变量会导致:</p>
<div class="itemizedlist">
<ul>
<li>
<p>程序将产生翻译成本地语言的输出</p>
</li>
<li>
<p>正确的将字符分类为字母、数字和其它类,这样做是必要的,可以让 Bash 在非英语 locale 下正确接收命令行输入的非 ASCII 字符。</p>
</li>
<li>
<p>为指定的国家设置正确的字母排序</p>
</li>
<li>
<p>适当的默认页面大小</p>
</li>
<li>
<p>为货币、时间和日期值设置正确的格式</p>
</li>
</ul>
</div>
<p>
这个脚本还设置了 <tt class="envar">INPUTRC</tt> 环境变量,让 Bash 和 Readline 使用我们先前创建的 <tt class="filename">/etc/inputrc</tt> 文件。</p>
<p>
把下面的 <em class="replaceable"><tt>[ll]</tt></em> 换成您想要设置的两个字母的语言代码(例如“en”),把 <em class="replaceable"><tt>[CC]</tt></em> 换成适当的两个字母的国家代码(例如“GB”),把 <em class="replaceable"><tt>[charmap]</tt></em> 换成规范的字符映射表。</p>
<p>
Glibc 支持的所有列表可以使用下列命令获得:</p>
<pre class="userinput"><kbd class="command">locale -a</kbd></pre>
<p>
很多 locale 有许多别名,比如 “<span class="quote">ISO-8859-1</span>” 也被称为
“<span class="quote">iso8859-1</span>” 和
“<span class="quote">iso88591</span>”。一些应用程序不能正确的处理这些别名,所以安全的做法是使用 locale 的规范名称。要确定正确的规范名称,运行下面的命令,并把其中的 <em class="replaceable"><tt>[locale name]</tt></em> 替换成
<span><strong class="command">locale -a</strong></span> 命令的输出中你感兴趣的 locale (在这个例子中是 “<span class="quote">en_GB.iso88591</span>”)</p>
<pre class="userinput"><kbd class="command">LC_ALL=<em class="replaceable"><tt>[locale name]</tt></em> locale charmap</kbd></pre>
<p>
对于 “<span class="quote">en_GB.iso88591</span>”
locale,上面的命令将会打印:</p>
<pre class="screen">ISO-8859-1</pre>
<p>
这样你就得到了正确的 locale 设置是 “<span class="quote">en_GB.ISO-8859-1</span>”</p>
<p>
确定了正确的 locale 名称后,创建
<tt class="filename">/etc/profile</tt> 文件:</p>
<pre class="userinput"><kbd class="command">cat > /etc/profile << "EOF"
<tt class="literal"># Begin /etc/profile
export LANG=<em class="replaceable"><tt>[ll]</tt></em>_<em class="replaceable"><tt>[CC]</tt></em>.<em class="replaceable"><tt>[charmap]</tt></em>
export INPUTRC=/etc/inputrc
# End /etc/profile</tt>
EOF</kbd></pre>
<div class="note">
<div class="admonhead">
<img alt="[Note]" src="../images/note.png" />
<h3 class="admontitle">
注意 </h3>
</div>
<div class="admonbody">
<p>“C”(默认值)和“en_US”(美国英语用户的推荐值)这两个 locale 是不同的。</p>
</div>
</div>
<p>设置键盘布局、屏幕字体和 locale 相关的环境变量,是使用一般的单字节编码和从左至右书写方式地区所需的国际化步骤。更复杂的情况(包括基于 UTF-8 的 locale)需要更多的步骤和补丁,因为这种情况下许多程序可能工作不正常。这些步骤和补丁没有包含在本书里,因此 LFS 无法支持这些 locale。</p>
</div>
<div class="navfooter">
<ul>
<li class="prev">
<a accesskey="p" href="inputrc.html" title="Creating the /etc/inputrc File">后退</a>
<p>
Creating the /etc/inputrc File
</p>
</li>
<li class="next">
<a accesskey="n" href="hostname.html" title="Configuring the localnet Script">前进</a>
<p>
Configuring the localnet Script
</p>
</li>
<li class="up">
<a accesskey="u" href="chapter07.html" title="Chapter 7. 配置系统启动脚本(Bootscripts)">上一级</a>.
</li>
<li class="home">
<a accesskey="h" href="../index.html" title="Linux From Scratch - Version 6.1">回首页</a>.
</li>
</ul>
</div>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -