如果我们想测试一个文件temp1是否存在以及另一个文件temp2是否不在在,可以使用以下代码:
if test -f "temp1"; then
echo "The file temp1 exist!"
else
echo "The file temp1 doesn't exist!"
fi
if test ! -f "temp2"; then
echo "The file temp2 doesn't exist!"
else
echo "The file temp2 exists!"
fi
运行结果如下: