0
0
Bash Scriptingscripting~20 mins

until loop in Bash Scripting - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Until Loop Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2: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
A
1
2
3
4
B
1
2
3
C
1
2
DNo output
Attempts:
2 left
💡 Hint
The loop runs until the condition becomes true, so it stops when count is greater than 3.
📝 Syntax
intermediate
2: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
AMissing 'do' keyword after until condition
BIncorrect use of ((count++))
CMissing 'done' keyword at the end
DUsing -eq instead of -lt in condition
Attempts:
2 left
💡 Hint
Check the structure of the until loop syntax.
🔧 Debug
advanced
2: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?
AThe variable 'count' is never incremented inside the loop
BThe condition is always true
CThe 'done' keyword is missing
DThe test command syntax is incorrect
Attempts:
2 left
💡 Hint
Check if the loop changes the variable controlling the condition.
🚀 Application
advanced
2:00remaining
Using until loop to wait for a file
Which script waits until a file named 'ready.txt' exists, then prints 'File is ready'?
A
while [ ! -f ready.txt ]; do sleep 1; done
echo "File is ready"
B
until [ ! -f ready.txt ]; do sleep 1; done
echo "File is ready"
C
while [ -f ready.txt ]; do sleep 1; done
echo "File is ready"
D
until [ -f ready.txt ]; do sleep 1; done
echo "File is ready"
Attempts:
2 left
💡 Hint
The until loop runs while the condition is false, so it waits until the file exists.
🧠 Conceptual
expert
3: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"
AInfinite loop without any output
BPrints success message immediately without any attempts
CPrints 'Attempt 1 failed' repeatedly until ping succeeds, then prints success message with count
DRuns once and prints 'Attempt 1 failed' then exits without success message
Attempts:
2 left
💡 Hint
The until loop runs while the command returns failure (non-zero exit).