开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜