Why use $HOME over ~ (tilde) in a shell script?
Is there any reason to use the variable $HOME
instead of a simple ~
(tilde) in a shell script?开发者_StackOverflow
Tilde expansion doesn't work in some situations, like in the middle of strings like /foo/bar:~/baz
Portability and uniformity of $HOME
. Tilde is a typing shortcut.
Today I found tilde expansion doesn't work in double quotation(""
).
In zsh(sorry I didn't check the behavior of other shells.),
Inside double quotes (
""
), parameter and command substitution occur
Tilde expansion is a filename expansion, so it fails inside double quotation.
$HOME
is a parameter substitution and can be expanded inside double quotation.
$HOME
is a safe bet.
精彩评论