What does the command CD do?
Solution 1:
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.
Solution 2:
It's trying to do the right thing and translate your "cd" command to lowercase. Regrettably, that's pretty pointless as it runs in a subshell. The remainder has to do with understanding bash.