I'm looking at writing something that handles changing directory in the calling shell and wanted to take a look at the cd command.
which cd
comes back with nothing and
man cd
does nothing either.
Where is the cd command?
I can see why it wouldn't be with the rest of the commands in /bin as it wouldn't change the directory in the calling shell if it was run in a sub-shell like the other commands are.
Is it part of the kernel?
If so would it be possible to write a kernel module to do what I want? I've been looking at tutorials on kernel programming but haven't found anything that tells me if I can extend the basic Unix command set this way. Most of the examples seem to be driver oriented or basic hello world examples writing to the logs.
Thanks. I've already written this (PushPop) in Korn shell and it works very well but is of course now dependent on the user being a Korn shell user. I now want to implement the project independently of the user's login shell.
Hi Perderabo
Thanks that's really helpful.
Could you elaborate a little more? As a Korn shell user, when I type cd is the Korn shell using a built in to call chdir()? So every shell such as bash and C etc has its own wrapper called cd?
'cd' command is not part of the kernel. though it is the part of the shell. Its a shell built-in. The other commands are external to the shell like 'file', 'find' . If a command is shell built-in the shell can invoke it directly . But if its outside the shell, the shell normally creates another process. As pointed above, almost all the commands (userspace) utilities like shell, daemon processes, commands (file, find, etc) uses system calls which in turn is in kernel space.