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!
Like @zane-hooper, I've had a similar problem on NFS. On parallel / distributed filesystems the lag between you creating a file on one machine and the other machine "seeing" it can be very large, so I could wait up to a full minute after the creation of the file before the while loop exits (and there also is an aftereffect of it "seeing" an already deleted file).
This creates the illusion that the script "doesn't work", while in fact it is the filesystem that is dropping the ball.
This took me a while to figure out, hope it saves somebody some time.
PS This also causes an annoying number of "Stale file handler" errors.
I had the same problem, put the ! outside the brackets;
while ! [ -f /tmp/list.txt ];
do
echo "#"
sleep 1
done
Also, if you add an echo inside the loop it will tell you if you are getting into the loop or not.