While loop to test if a file exists in bash

前端 未结 8 552
旧巷少年郎
旧巷少年郎 2020-12-23 10:37

I\'m working on a shell script that does certain changes on a txt file only if it does exist, however this test loop doesn\'t work, I wonder why? Thank you!



        
8条回答
  •  鱼传尺愫
    2020-12-23 11:18

    works with bash and sh both:

    touch /tmp/testfile
    sleep 10 && rm /tmp/testfile &
    until ! [ -f /tmp/testfile ]
    do
       echo "testfile still exist..."
       sleep 1
    done
    echo "now testfile is deleted.."
    

提交回复
热议问题