Tilde expansion
Jump to navigation
Jump to search
A shell will perform tilde expansion when it encounters a tilde symbol (~) at the start of a word, usually replacing it with a user's home directory.
For a tilde to be considered for expansion at the start of a word, the tilde must be both unquoted and unescaped.
- If encountered by itself, the shell will substitute the value of the shell variable $HOME for tilde, and if it is empty or not present, the shell will substitute the home directory of the user calling the shell.
- If the tilde is followed immediately by a word, it is treated as a user name; the tilde is subtituted by the home directory of the specified user, so long as it is a valid login name.
Shells such as bash [1] and zsh [2] provide additional functionality of tilde expansion, such as moving within directory stacks and globbing.
See also
Bash Reference Manual: Tilde Expansion
A User's Guide to the Z-Shell: Substitutions