Bird
0
0

You want to write a script that waits until a file named done.txt exists before continuing. Which until loop is correct?

hard🚀 Application Q8 of 15
Bash Scripting - Loops
You want to write a script that waits until a file named done.txt exists before continuing. Which until loop is correct?
Auntil [ -f done.txt ]; do echo "Waiting..."; sleep 1; done
Buntil [ -r done.txt ]; do echo "Waiting..."; sleep 1; done
Cuntil [ -d done.txt ]; do echo "Waiting..."; sleep 1; done
Duntil [ ! -f done.txt ]; do echo "Waiting..."; sleep 1; done
Step-by-Step Solution
Solution:
  1. Step 1: Understand the goal

    The script should wait until the file exists, so it should loop while the file does not exist.
  2. Step 2: Choose correct condition

    until [ -f done.txt ]; do echo "Waiting..."; sleep 1; done loops while [ -f done.txt ] returns non-zero (file missing), stopping when the condition returns zero (file exists).
  3. Final Answer:

    until [ -f done.txt ]; do echo "Waiting..."; sleep 1; done -> Option A
  4. Quick Check:

    Loop runs while file missing, stops when file exists [OK]
Quick Trick: Use until [ -f file ] to loop while file missing [OK]
Common Mistakes:
MISTAKES
  • Using -d for file instead of -f
  • Using ! -f which reverses the logic

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes