以下不返回任何内容:
which asdf
那么为什么这里会触发 if 语句呢?
x=$(which asdf)
if [ -f $x ]; then echo "exists"; fi
最佳答案
你没有引用 $x
,所以你的测试变成了 [ -f ]
,这是真的,因为 -f
是一个非- 空字符串。
if [ -f "$x" ]; then
关于bash - 关于 bash 文件的混淆存在测试操作符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57168341/