早期的 Unix Shell 是否使用过 `chd` 命令来切换目录?

3作者: damiaozi7 个月前
我一直在探索早期的 Unix 系统,特别是使用 SIMH 模拟器的 *PDP-7 上的 Unix V0* 及其后继版本 *PDP-11 上的 Unix V1*。<p>有趣的是,现代 shell 中最常用的命令之一 `cd` 在这些早期版本中 *并不* 存在。<p>- 在 *Unix V0* 中,目录切换是通过一个名为 `ch` 的 shell 命令完成的,该命令与一个名为 `dd`(directory directory,目录目录)的特殊目录结合使用。例如,要进入 Ken 的主目录,需要输入 `ch dd ken`。这似乎反映出当时还没有实现完整的层次文件结构。我已经在 SIMH 模拟器中验证了这种行为。<p>- 在 *Unix V1* 中,方法变得更加熟悉:你使用 `chdir /usr/ken`,但仍然 *不是* `cd`。这也在 SIMH 上得到了验证。Dennis Ritchie 在《Unix 分时系统的演变》中提到:<p>&gt; “顺便说一句,_chdir_ 被拼写为 _ch_;我不记得当我们转向 PDP-11 时为什么会扩展它。”<p>现在,有趣的地方来了:<p>在阅读 [Unix V0 shell 源代码 (`pbsh.s`)](https://github.com/DoctorWkt/pdp7-unix/blob/master/src/other/pbsh.s#L199C1-L210C18) 时,我发现了一些似乎在检查与字符串 `“chdir”` 匹配的内置命令的东西——但它比较的是前 3 个字符,而不是 2 个或 5 个:<p>```asm &quot; https://github.com/DoctorWkt/pdp7-unix/blob/master/src/other/pbsh.s#L199C1-L210C18<p>chdirstr: &lt;ch&gt;;&lt;di&gt;;&lt;r 040<p>. . . . . .<p>&quot; 检查内置的 &quot;chdir&quot; 命令 lac argv0 sad chdirstr skp jmp 1f lac argv0+1 sad chdirstr+1 skp jmp 1f lac argv0+2 sad chdirstr+2 jmp changedir ```<p>这种逻辑表明它应该匹配类似 `chd` 的字符串——因为只比较了前 3 个字符(`argv0`、`argv0+1`、`argv0+2`)。<p>然而,当在 SIMH 中运行 Unix V0 时,我只能让 `ch` 工作——`chd` 似乎没有被识别为命令。这似乎与 shell 源代码所暗示的相矛盾。<p>有人在早期的 Unix shell 中看到过 `chd` 被记录或工作吗?<p>很想听听其他探索过这一层 Unix 考古学的人的意见。
查看原文
I&#x27;ve been exploring early Unix systems, particularly *Unix V0 on the PDP-7* and its successor, *Unix V1 on the PDP-11*, using the SIMH emulator.<p>Interestingly, one of the most common modern shell commands, `cd`, did *not* exist in these early versions.<p>- In *Unix V0*, directory changes were done via a shell command called `ch`, used in combination with a special directory called `dd`(directory directory). For example, to enter Ken&#x27;s home directory, one would type `ch dd ken`. This seems to reflect that a full hierarchical file structure hadn&#x27;t been implemented yet. I&#x27;ve verified this behavior in the SIMH emulator.<p>- In *Unix V1*, the method becomes more familiar: you use `chdir &#x2F;usr&#x2F;ken`, though still *not* `cd`. This is also verified on SIMH. Dennis Ritchie mentioned in _&quot;The Evolution of the Unix Time-sharing System&quot;_:<p>&gt; &quot;Incidentally, _chdir_ was spelled _ch_; why this was expanded when we went to the PDP-11 I don&#x27;t remember.&quot;<p>Now here&#x27;s where it gets curious:<p>While reading the [Unix V0 shell source code (`pbsh.s`)](https:&#x2F;&#x2F;github.com&#x2F;DoctorWkt&#x2F;pdp7-unix&#x2F;blob&#x2F;master&#x2F;src&#x2F;other&#x2F;pbsh.s#L199C1-L210C18), I found something that seems to check for a built-in command matching the string `&quot;chdir&quot;` — but compares the first 3 characters, NOT 2 or 5:<p>```asm &quot; https:&#x2F;&#x2F;github.com&#x2F;DoctorWkt&#x2F;pdp7-unix&#x2F;blob&#x2F;master&#x2F;src&#x2F;other&#x2F;pbsh.s#L199C1-L210C18<p>chdirstr: &lt;ch&gt;;&lt;di&gt;;&lt;r 040<p>. . . . . .<p>&quot; check for built-in &quot;chdir&quot; command lac argv0 sad chdirstr skp jmp 1f lac argv0+1 sad chdirstr+1 skp jmp 1f lac argv0+2 sad chdirstr+2 jmp changedir ```<p>This logic suggests it would match a string like `chd` — since only the first 3 characters are compared (`argv0`, `argv0+1`, `argv0+2`).<p>However, when running the Unix V0 in SIMH, I can only get `ch` to work — `chd` doesn&#x27;t appear to be recognized as a command. This seems contradictory with what the shell source implies.<p>Has anyone seen `chd` documented or working in early Unix shells?<p>Would love to hear from others who have explored this layer of Unix archaeology.