Tilde substitution
After the shell performs alias substitution, it checks each word
to see if it begins with an unquoted tilde (~
). If it does,
the shell checks the word, up to the first slash (/
), to
see if it matches a user name in the /etc/passwd file.
If the shell finds a match, it replaces the ~
character and
the name with the login directory of the matched user. This process is called tilde
substitution.
The shell does not change the original text if it does not find a match.
The Korn shell also makes special replacements if the ~
character
is the only character in the word or followed by plus sign (+
)
or hyphen (-
):
Item | Description |
---|---|
~ |
Replaced by the value of the HOME variable |
~+ |
Replaced by the $PWD variable (the full path name of the current directory) |
~- |
Replaced by the $OLDPWD variable (the full path name of the previous directory) |
In addition, the shell attempts tilde substitution when the value of a
variable assignment parameter begins with a tilde ~
character.