正在等待用bash编写文件?

正在等待用bash编写文件?,bash,shell,Bash,Shell,我有以下代码: while [ ! -f testfile.p ] do sleep 1 echo "working" done [ ! -f testfile.p ] && echo "exists" || echo "doesn't exist" 当我执行ls时,我看到testfile.p存在。然而,这是行不通的。循环永远不会结束。当我尝试使用以下代码测试它时: while [ ! -f testfile.p ] do sleep 1 ec

我有以下代码:

while [ ! -f testfile.p ]
do
    sleep 1
    echo "working"
done
[ ! -f testfile.p ] && echo "exists" || echo "doesn't exist"
当我执行
ls
时,我看到testfile.p存在。然而,这是行不通的。循环永远不会结束。当我尝试使用以下代码测试它时:

while [ ! -f testfile.p ]
do
    sleep 1
    echo "working"
done
[ ! -f testfile.p ] && echo "exists" || echo "doesn't exist"
我得到的只是“不存在”


关于可能出现的错误或如何排除故障,您有什么想法吗?

testfile.p
可能不是常规文件。它是目录、套接字还是特殊设备?如果
testfile.p
是常规文件,
[!-f testfile.p]
evals false,因此
不存在
。您的测试和您的问题都有问题。您的测试代码是向后的-如果不向后,它将回显存在,反之亦然。如果您尝试过帮助测试,您应该看到针对您的请求的正确测试应该是
-e
-a
。它可能像脚本在错误目录中运行时使用
一样简单。