POSIX defines that...
cd was not given any arguments, it will use the value of
$HOME if the variable is set, and do nothing otherwise (although it also says that results are unspecified). —
...if an argument is
~ or begins with
~/, the tilde will be expanded to the value of
$HOME if the variable is set; the results are unspecified otherwise. —
$HOME is set, then all three commands are equivalent. (Extra slashes after directory names are meaningless.)
$HOME is not set, then the results of both
cd are unspecified:
In bash, AT&T ksh, and Heirloom sh, plain
cd will fail with "no home directory".
In csh, zsh, dash, and MirBSD mksh, plain
cd will do nothing.
In tcsh, plain
cd will look up the home directory using
As for the
bash and tcsh will expand
~ to the home directory from
AT&T ksh will expand
~ to your username (?!).
In csh and zsh,
~ will expand to an empty string. (
cd ~ will therefore do nothing, like plain
cd, in those shells.)
In dash and MirBSD mksh, the
~ will remain a literal
cd ~ will try to change to a directory named such.)
Heirloom sh never expands
~ even if
$HOME is set – it probably predates the convention.
Out of these, only csh and zsh stick to the POSIX definition of expanding
~ to the value of
$HOME even if it is empty.
(The fish shell always sets
getpwnam() on startup if the variable empty, and refuses to modify it afterwards.)