Challenge - 5 Problems
Until Loop Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
Output of a simple until loop
What will be the output of this Bash script?
Bash Scripting
count=1 until [ $count -gt 3 ] do echo $count ((count++)) done
Attempts:
2 left
💡 Hint
The loop runs until the condition becomes true, so it stops when count is greater than 3.
✗ Incorrect
The until loop runs while the condition is false. Here, it runs while count is less than or equal to 3, printing 1, 2, and 3.
📝 Syntax
intermediate2:00remaining
Identify the syntax error in the until loop
Which option contains a syntax error in the until loop?
Bash Scripting
count=0 until [ $count -eq 5 ] echo $count ((count++)) done
Attempts:
2 left
💡 Hint
Check the structure of the until loop syntax.
✗ Incorrect
The 'do' keyword is required after the until condition to start the loop body.
🔧 Debug
advanced2:00remaining
Why does this until loop run infinitely?
Consider this script:
count=1
until [ $count -gt 5 ]
do
echo $count
done
Why does it run forever?
Attempts:
2 left
💡 Hint
Check if the loop changes the variable controlling the condition.
✗ Incorrect
Since 'count' is never increased, the condition never becomes true, so the loop never stops.
🚀 Application
advanced2:00remaining
Using until loop to wait for a file
Which script waits until a file named 'ready.txt' exists, then prints 'File is ready'?
Attempts:
2 left
💡 Hint
The until loop runs while the condition is false, so it waits until the file exists.
✗ Incorrect
Option D waits until the file exists (-f ready.txt is true), then exits the loop and prints the message.
🧠 Conceptual
expert3:00remaining
Behavior of until loop with command exit status
What does this script print?
count=1
until ping -c1 -W1 8.8.8.8 >/dev/null 2>&1
echo "Attempt $count failed"
((count++))
done
echo "Ping successful after $count attempts"
Attempts:
2 left
💡 Hint
The until loop runs while the command returns failure (non-zero exit).
✗ Incorrect
The loop repeats ping attempts until it succeeds. Each failure prints a message and increments count. When ping succeeds, loop ends and success message prints.