0

How can I check if the file exists. I tried something with the until loop but I couldn't, it's not working properly. What I want to do is to have the file I specified in a folder. If not, I want it to go into an infinite loop. exit the loop if it exists

I leave the code I tried below

while ! find /mnt/c -name 'file*.msixbundle' 1> /dev/null 2>&1
do
echo "file not found"
done
Grau
  • 73
  • 5
  • 1
    Does this answer your question? [How do I tell if a regular file does not exist in Bash?](https://stackoverflow.com/questions/638975/how-do-i-tell-if-a-regular-file-does-not-exist-in-bash) – kiner_shah Dec 30 '21 at 08:12
  • The loop does not make sense. Unless some magic process creates the file during the loop, the `find` command will always produce the same exit code. Aside from this, you can't derive from the exit status of `find`, whether a file was found. – user1934428 Dec 30 '21 at 08:19
  • @user1934428 He/she''s guessing syntax. – konsolebox Dec 30 '21 at 08:44
  • 1
    @Grau At least insert a sleep command in between loops if you deliberately want to do that and fry either your CPU or your storage. Relying on inotify is a better solution. – konsolebox Dec 30 '21 at 08:46
  • I've already asked because I want to use a while loop instead of if, but I guess the moderator says you should do it with if. If I wanted to do it with if, I wouldn't have asked my question anyway. it is a sad situation. – Grau Dec 30 '21 at 09:40

0 Answers0