While loop to test if a file exists in bash

前端 未结 8 563
旧巷少年郎
旧巷少年郎 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:22

    When you say "doesn't work", how do you know it doesn't work?

    You might try to figure out if the file actually exists by adding:

    while [ ! -f /tmp/list.txt ]
    do
      sleep 2 # or less like 0.2
    done
    ls -l /tmp/list.txt
    

    You might also make sure that you're using a Bash (or related) shell by typing 'echo $SHELL'. I think that CSH and TCSH use a slightly different semantic for this loop.

提交回复
热议问题