~ 正在被 bash 中的变量值替换
~ is being replaced by a variable's value in bash
所以我有一个脚本可以做到这一点
wget firefoxDownloadLink -o ~/firefox
mkdir ~/firefox-17
cd ~/firefox-17
tar xjf ~/firefox-17.0.1.tar.bz2
我明白了,但不知道为什么:
cd: context: No such file or directory
mkdir: cannot create directory `context/firefox-17': No such file or directory
cd: context/firefox-17: No such file or directory
tar (child): context/firefox-17.0.1.tar.bz2: Cannot open: No such file or directory
我已经用显示在那里的上下文值设置了一个变量,但我不明白为什么 ~
被替换为该值。如果我不设置该值,它可以正常工作,但现在我需要它。
对可能发生的事情有什么建议吗?
~
替换为 $HOME
的值,通常指向您的主目录。看起来你已经覆盖了 $HOME
.
来自 bash 手册页:
If a word begins with an unquoted tilde character (~
), all of the characters preceding the first unquoted slash (or all characters, if there is no unquoted slash) are considered a tilde-prefix. If none of the characters in the tilde-prefix are quoted, the characters in the tilde-prefix following the tilde are treated as a possible login name. If this login name is the null string, the tilde is replaced with the value of the shell parameter HOME
. If HOME
is unset, the home directory of the user executing the shell is substituted instead. Otherwise, the tilde-prefix is replaced with the home directory associated with the specified login name.
所以我有一个脚本可以做到这一点
wget firefoxDownloadLink -o ~/firefox
mkdir ~/firefox-17
cd ~/firefox-17
tar xjf ~/firefox-17.0.1.tar.bz2
我明白了,但不知道为什么:
cd: context: No such file or directory
mkdir: cannot create directory `context/firefox-17': No such file or directory
cd: context/firefox-17: No such file or directory
tar (child): context/firefox-17.0.1.tar.bz2: Cannot open: No such file or directory
我已经用显示在那里的上下文值设置了一个变量,但我不明白为什么 ~
被替换为该值。如果我不设置该值,它可以正常工作,但现在我需要它。
对可能发生的事情有什么建议吗?
~
替换为 $HOME
的值,通常指向您的主目录。看起来你已经覆盖了 $HOME
.
来自 bash 手册页:
If a word begins with an unquoted tilde character (
~
), all of the characters preceding the first unquoted slash (or all characters, if there is no unquoted slash) are considered a tilde-prefix. If none of the characters in the tilde-prefix are quoted, the characters in the tilde-prefix following the tilde are treated as a possible login name. If this login name is the null string, the tilde is replaced with the value of the shell parameterHOME
. IfHOME
is unset, the home directory of the user executing the shell is substituted instead. Otherwise, the tilde-prefix is replaced with the home directory associated with the specified login name.