【发布时间】:2010-09-28 04:45:49
【问题描述】:
我正在尝试确定文件或目录是否不存在。我尝试了以下命令来查看文件是否存在并且它们是否正常工作:
if [ -a 'settings.py' ]; then echo 'exists'; fi
exists #output
if [ -a 'foo' ]; then echo 'exists'; fi #outputs nothing
但是当我尝试这个时:
if [ ! -a 'settings.py' ]; then echo 'does not exist'; fi
does not exist #shouldn't be output since the file does exist
if [ ! -a 'foo' ]; then echo 'does not exist'; fi
does not exist
无论如何都会输出'不存在'。
【问题讨论】: