<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml xml:lang="zh">
<head>
<meta http-equiv="Content-Type" content="text/vnd.wap.wml; charset=utf-8"/>
<meta http-equiv="Cache-Control" content="no-cache"/></head>
<card title="Shell 不是 BASH，BASH 是 Shell - Gracecode.com">
<p>标题听起来像是在绕口令，不过很多兄弟都会将 BASH、CSH 和 ZSH 以及 Shell 之间的关系搞混。本人似乎又在“误人子弟”了，下面是我和 <a href="http://thomas.x.iverson.blog.163.com" title="http://thomas.x.iverson.blog.163.com">ghosTM55 兄弟</a>的一些聊天记录，整理如下。</p>

<pre>ghosTM55: 自动补全是 Shell 极为有用的一项拓展功能 ，这句话有没有错？
手气不错: 应该是 BASH，Shell 是一个接口，而不是程序
ghosTM55: 好的，明白了。那么为什么有 Shell 分类这种说法呢？
手气不错: Shell 的主要功能就是封装内核和系统调用，提供统一的接口供
          用户使用。比如你编辑 /etc/passwd 更改用户默认的 shell 为
          ls，那么就显示一下当前用户目录就退出了。这是因为 ls 发送
          了 Shell 退出同样的信号（通常为 EXIT_SUCCESS）。
ghosTM55: 对
手气不错: 同时 Shell 会在幕后做很多的事情。比如你在 Shell 中输入 ls
          回车。它要做的事情首先就是在 PATH 中寻找 ls 程序。
ghosTM55: 恩
手气不错: 然后 exec() 运行 ls，等待 ls 返回，然后 shell 获得 ls 的
          退出返回值（信号），程序结束。
          这你可以看 time ls 就知道，有一个用户进程和内核进程的概念。
          大致的流程就这样，不过通常 shell 要做的事情比上述要做的事
          情要复杂得多。
ghosTM55: 那么 Shell 的种类这种讲法是不存在的？
手气不错: 这就回到上面所提到的了，shell 我个人认为是一个接口，可以有
          不同的实现（有一个叫 POSIX 标准的东西），对比 bash、csh、
          zsh 等等这些 Shell，这就像虚拟终端（Virtual Terminals）有 
          xterm、rxvt 一样。所以，引证上面的话，说终端都有半透明功能，
          这是不正确的 - 有可能就 rxvt 有这样的功能。
ghosTM55: 哦</pre><p>简而言之，可以用下面的图来理解 内核 - Shell - 应用程序 - 用户 之间的的关系（图片引自<a href="http://nl.opensuse.org/Concepts#Linux_shell_.2F_Commandoregel-interface" title="http://nl.opensuse.org/Concepts#Linux_shell_.2F_Commandoregel-interface">这里</a>）。</p>

<p><img src="http://photo14.yupoo.com/20080109/193724_536750136.jpg" alt="http://photo14.yupoo.com/20080109/193724_536750136.jpg" title="http://photo14.yupoo.com/20080109/193724_536750136.jpg" /></p>

<p>想更深入了解 Shell 机制的，可以参看<a href="http://www.linuxsir.org/main/?q=node/135" title="http://www.linuxsir.org/main/?q=node/135">这里</a>和<a href="http://linux.vbird.org/linux_basic/0320bash/0320bash.php" title="http://linux.vbird.org/linux_basic/0320bash/0320bash.php">这里</a>。</p>

<p>更正：感谢寂寞烈火等兄弟的<a href="http://bbs.chinaunix.net/thread-1040253-1-1.html" title="http://bbs.chinaunix.net/thread-1040253-1-1.html">指正</a>，“应该是 BASH，Shell 是一个接口，而不是程序”这句话是 <strong>错误</strong> 的。应该是：</p>

<pre>理论上，只要你愿意，任何一个程序都可以作为你的 Shell。- 引自 r2007 兄弟</pre>
<p>
<a href="http://www.gracecode.com/wap/">Gracecode.com</a> |
<a href="http://www.gracecode.com/wap/d/600 ">Permalink</a>(<a href="http://www.gracecode.com/Archive/Display/600 ">xHTML</a>) |
<a href="http://www.gracecode.com/Trackback/Recieve/600/zij0xx">Trackback</a> |
<a href="http://rss.gracecode.com">Rss</a>
</p>
</card>
</wml>