Why is this?
When I do this
CD ~/Desktop It doesn't take me to the Desktop. But this:
echo "foo bar" | GREP bar gives me:
bar From your other questions I take it you're using OS X. The default HFS+ filesystem on OS X is case-insensitive: you can't have two files called "abc" and "ABC" in the same directory, and trying to access either name will get to the same file. The same thing can happen under Cygwin, or with case-insensitive filesystems (like FAT32 or ciopfs) anywhere.
Because grep is a real executable, it's looked up on the filesystem (in the directories of PATH). When your shell looks in /usr/bin for either grep or GREP it will find the grep executable.
Shell builtins are not looked up on the filesystem: because they're built in, they are accessed through (case-sensitive) string comparisons inside the shell itself.
What you're encountering is an interesting case. While cd is a builtin, accessed case-sensitively, CD is found as an executable /usr/bin/cd. The cd executable is pretty useless: because cd affects the current shell execution environment, it is always provided as a shell regular built-in, but there is a cd executable for POSIX's sake anyway, which changes directory for itself and then immediately terminates, leaving the surrounding shell where it started.
You can try these out with the type builtin:
$ type cd cd is a shell builtin $ type CD CD is /usr/bin/CD type tells you what the shell will do when you run that command. When you run cd you access the builtin, but CD finds the executable. For other builtins, the builtin and the executable will be reasonably compatible (try echo), but for cd that isn't possible.
alias GREPorwhich GREPoutput anything.GREP, which is distinct fromgrep. (True, it may just be a hard link or symbolic link to/usr/bin/grep, but from the shell's standpoint, it's a separate command.)bashmight ask for a file namedGREP, but the file system considersgrepa match.