Home » Questions » Computers [ Ask a new question ]

What does the command CD do?

What does the command CD do?

Not realising I had caps-lock on, I typed CD into the command prompt on my mac. Surprisingly, it didn't error.

Asked by: Guest | Views: 102
Total answers/comments: 1
Guest [Entry]

"Seems it doesn't do much at all:

Apple mailing list link

""I'm going on some old memories here, so I cannot provide a very
detailed explanation, but the reason /usr/bin/cd exists is due
to a POSIX requirement that relates to aliases and being able to
not use an alias via escaping. But /usr/bin/cd is a useless
script since if you run cd within a shell script the directory
change only applies to the subshell under which the script runs.
cd cannot be a shell script.

Also, the script is a generic script in that it is used for a
number of commands and not just cd.

I noticed that /usr/bin/cd has a hard link count of 15 on my
10.4 system [...]""

Further down in that thread:

""A friend of mine told me the ""${0##*/}"" means ""take the command, but remove its path"" (i.e., convert ""/usr/bin/cd"" to ""cd"").""

So it seems the script removes the path, converts the result to lower case and then appends the original arguments."