1

考虑以下 Bash 脚本:

function dosomething {
    local fname="~/.bash_profile"
    if [[ -f "$fname" ]]; then
        echo "proceeding"
    else
        echo "skipping"
    fi
}

dosomething

尽管我知道 ~/.bash_profile 存在,但我总是被“跳过”。为什么?

4

1 回答 1

10

~仅在未引用时才由 shell 扩展。当它被引用时,它是一个文字波浪符号。

local fname=~/.bash_profile
于 2018-09-26T14:11:50.067 回答