开发者

Why use $HOME over ~ (tilde) in a shell script?

开发者 https://www.devze.com 2023-03-04 00:05 出处:网络
Is there any reason to use the variable $HOME instead of a simple ~ (tilde) in a shell script?开发者_StackOverflowTilde expansion doesn\'t work in some situations, like in the middle of strings like /

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

精彩评论

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

关注公众号