Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试检测是否semester1 (2013).csv存在名为的文件。
semester1 (2013).csv
到目前为止,我有以下内容:
file="results/semester1\ (2013).csv" if [ -f $file ]; then echo 'File exists.' fi
这会产生以下错误:
binary operator expected
我没有正确逃避什么?
你逃避太多,但引用不够:
file="results/semester1 (2013).csv" if [ -f "$file" ]; then echo 'File exists.' fi
如果您不引用"$file",它将在测试中扩展为两个“单词”,并且失败。有了引号,它就可以全部通过测试了。
"$file"