News for hackers. Stuff that matters.
Re:Really Friendly Command Line Intro by gizmo686 on Sunday July 08, 2018 @03:04PM (#17485504)
cd itself is implemented by the shell (granted, it is mostly just a syscall). You can't fork and exec a cd program because it would need to change the parent's working directory.

Also, bash offers a directory stack you can use:

pushd pushes the current directory to the stack and cd`s to the specified directory.

popd pops the top directory from the stack and cd`s into it.

Not quite the same thing as cd -, but still useful to know.

Re:Really Friendly Command Line Intro by schoen on Sunday July 08, 2018 @03:32PM (#17485678)
> cd itself is implemented by the shell (granted, it is mostly just a syscall).

Right, the distinction I was drawing is just that the shell potentially does chdir("..") when you run "cd ..", but it can't do chdir("-") when you run "cd -". It's true that in both cases the shell has to make the chdir syscall rather than running an external program.

I just did "strace -e chdir bash" and noticed that in fact, my shell doesn't do chdir("..") at all in practice, presumably because it wants to maintain a clean notion of PWD that doesn't contain a complex series of relative paths.

Re:Really Friendly Command Line Intro by jolmg on Sunday July 08, 2018 @10:10PM (#17487487)
> presumably because it wants to maintain a clean notion of PWD that doesn't contain a complex series of relative paths.

More probably, it's so that things don't get confusing for the user with symbolic links to directories. If you cd to a symbolic link that leads to a directory, `chdir("..")` goes to the parent of the target, while `cd ..` goes to the parent of the source. In other words, `cd dir/subdir/; cd ..` will always get you back to dir/, but if it used chdir("..") it wouldn't always.