早期的Unix Shell是否曾使用`chd`命令来更改目录?

3作者: damiaozi7 个月前原帖
我一直在探索早期的Unix系统,特别是*PDP-7上的Unix V0*及其后继版本*PDP-11上的Unix V1*,并使用SIMH模拟器进行研究。 有趣的是,在这些早期版本中,现代最常用的shell命令之一`cd`并不存在。 - 在*Unix V0*中,目录的更改是通过一个名为`ch`的shell命令来完成的,结合一个特殊的目录`dd`(directory directory)使用。例如,要进入Ken的主目录,可以输入`ch dd ken`。这似乎反映出当时尚未实现完整的层次文件结构。我已经在SIMH模拟器中验证了这一行为。 - 在*Unix V1*中,方法变得更加熟悉:你可以使用`chdir /usr/ken`,但仍然*不是*`cd`。这一点在SIMH中也得到了验证。丹尼斯·里奇在《Unix时间共享系统的演变》中提到: > “顺便提一下,_chdir_被拼写为_ch_;我不记得为什么在转到PDP-11时要扩展这个名称。” 现在事情变得有趣了: 在阅读[Unix V0的shell源代码(`pbsh.s`)](https://github.com/DoctorWkt/pdp7-unix/blob/master/src/other/pbsh.s#L199C1-L210C18)时,我发现了一些似乎是在检查与字符串`"chdir"`匹配的内置命令的代码——但它比较的是前3个字符,而不是2个或5个: ```asm chdirstr: <ch>;<di>;<r 040 . . . . . " check for built-in "chdir" 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 ``` 这个逻辑表明它会匹配像`chd`这样的字符串——因为只比较了前3个字符(`argv0`,`argv0+1`,`argv0+2`)。 然而,当我在SIMH中运行Unix V0时,我只能让`ch`工作——`chd`似乎并没有被识别为命令。这似乎与shell源代码所暗示的相矛盾。 有没有人见过`chd`在早期Unix shell中被记录或工作的情况? 我很想听听其他探索过这一层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.