<分区>
考虑以下 Bash 脚本:
function dosomething {
local fname="~/.bash_profile"
if [[ -f "$fname" ]]; then
echo "proceeding"
else
echo "skipping"
fi
}
dosomething
尽管我知道 ~/.bash_profile 存在,但我总是被“跳过”。为什么?
<分区>
考虑以下 Bash 脚本:
function dosomething {
local fname="~/.bash_profile"
if [[ -f "$fname" ]]; then
echo "proceeding"
else
echo "skipping"
fi
}
dosomething
尽管我知道 ~/.bash_profile 存在,但我总是被“跳过”。为什么?
最佳答案
~
只有在未加引号的情况下才会被 shell 扩展。当它被引用时,它是一个字面波浪符号。
local fname=~/.bash_profile
关于bash - 无法测试文件是否存在于 Bash 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52519705/