Nik*_*huk 1 bash tilde-expansion
请考虑以下Bash脚本:
function dosomething {
local fname="~/.bash_profile"
if [[ -f "$fname" ]]; then
echo "proceeding"
else
echo "skipping"
fi
}
dosomething
Run Code Online (Sandbox Code Playgroud)
虽然我知道〜/ .bash_profile存在,但我总是"跳过".为什么?
~如果它没有引用,它只会被shell扩展.当它被引用时,它是一个字面的波浪符号.
local fname=~/.bash_profile
Run Code Online (Sandbox Code Playgroud)