source code for unix environments 'cd' command
Asked Answered
P

4

10

Where can I find the source code for Unix environment's cd command?

I want to know how the command is implemented.

Partlow answered 19/5, 2009 at 8:24 Comment(0)
C
10

Here is a complete explanation how cd works: http://web.archive.org/web/20090515201659/http://www.cs.ucr.edu/~brett/cs153_w02/syscall.html

The cd Unix command just calls chdir and examines the error codes.

Cogitation answered 19/5, 2009 at 8:33 Comment(1)
@majidgeek: Thanks, fixed. I couldn't find a better link than the wayback machine :-/Cogitation
A
4

To see the source for the bash cd command, for example:

  1. Download the bash source from http://ftp.gnu.org/gnu/bash/
  2. Extract the source
  3. Examine bash-./builtins/cd.def, where "." represents the version you downloaded (e.g. 4.2). This is the file from which cd.c is created, according to the comment at the top of the file.
Alina answered 5/5, 2013 at 1:54 Comment(0)
M
2

cd is usually built-in in the shell, you should just look at the code of any shell, e.g. bash, or ash.

The cd command should be ultimately based on the chdir() function, but if you're interested in all the command line expansions, then the source is the shell.

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

Mithgarthr answered 19/5, 2009 at 8:28 Comment(2)
cd must be built into the shell, since you cannot change the working directory of the parent processQuicksilver
@1800INFORMATION, you gave me the answer to the question I didn't know how to ask.Demand
I
1

using chdir function:

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

Intellection answered 19/5, 2009 at 8:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.