9

我在哪里可以找到 Unix 环境cd命令的源代码?

我想知道命令是如何实现的。

4

4 回答 4

10

这是一个完整的解释如何cd工作:http ://web.archive.org/web/20090515201659/http://www.cs.ucr.edu/~brett/cs153_w02/syscall.html

cdUnix 命令只是调用并chdir检查错误代码。

于 2009-05-19T08:33:08.340 回答
4

要查看 bash cd 命令的源代码,例如:

  1. 从http://ftp.gnu.org/gnu/bash/下载 bash 源
  2. 提取源码
  3. 检查 bash- /builtins/cd.def,其中“ . ”代表您下载的版本(例如 4.2)。根据文件顶部的注释,这是从中创建 cd.c 的文件。
于 2013-05-05T01:54:30.840 回答
2

cd 通常内置在 shell 中,您应该只查看任何 shell 的代码,例如 bash 或 ash。

cd 命令最终应该基于 chdir() 函数,但如果您对所有命令行扩展感兴趣,那么源代码就是 shell。

http://en.wikipedia.org/wiki/Comparison_of_computer_shells

于 2009-05-19T08:28:46.163 回答
1

使用 chdir 函数:

http://www.opengroup.org/onlinepubs/009695399/functions/chdir.html

于 2009-05-19T08:25:19.337 回答