Shell – Expand ~, . and `..`

directoryshell

Since ~, . and .. are special directories, why are they handled differently in the following example?

$ echo ~
/home/tim
$ echo ..
..
$ echo .
.
  1. ~ is expanded into the dir, but the other two are not.
  2. The other two are expanded literally, but ~ isn't.

Best Answer

~ is a special name expanded by the shell, . and .. are real proper directory names, so no expansion is done by the shell there.

Related Question