0
0
Bash Scriptingscripting~20 mins

Infinite loops in Bash Scripting - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Infinite Loop Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this infinite loop script?
Consider this Bash script snippet. What will it output when run?
Bash Scripting
count=1
while true; do
  echo $count
  ((count++))
  if [ $count -gt 3 ]; then
    break
  fi
done
A
1
2
3
4
B
1
2
3
C
1
2
3
4
5
DNo output, infinite loop
Attempts:
2 left
💡 Hint
Look at the break condition inside the loop.
📝 Syntax
intermediate
2:00remaining
Which option causes a syntax error in this infinite loop?
Identify which Bash loop snippet will cause a syntax error.
Awhile :; do echo "Hello"; done
Bwhile (true) do echo "Hello"; done
Cwhile true; do echo "Hello"; done
Denod ;"olleH" ohce od ;eurt elihw
Attempts:
2 left
💡 Hint
Check the syntax of the while loop condition and keywords.
🔧 Debug
advanced
2:00remaining
Why does this infinite loop never stop?
Examine the script below. Why does it run forever without stopping?
Bash Scripting
i=0
while [ $i -lt 5 ]
do
  echo $i
done
AThe loop has no done keyword.
BThe condition syntax is wrong, causing infinite loop.
CThe echo command causes the loop to restart.
DVariable i is never incremented, so condition is always true.
Attempts:
2 left
💡 Hint
Check if the loop changes the variable controlling the condition.
🚀 Application
advanced
2:00remaining
Which script safely runs an infinite loop that can be stopped by Ctrl+C?
Select the Bash script that runs an infinite loop printing 'Running' every second and can be stopped by pressing Ctrl+C.
Awhile :; do echo "Running"; done
Bfor ((;;)); do echo "Running"; sleep 1; done
Cwhile true; do echo "Running"; sleep 1; done
Dwhile true; do echo "Running"; sleep 0; done
Attempts:
2 left
💡 Hint
Consider which loop includes a pause and allows interruption.
🧠 Conceptual
expert
2:00remaining
What is the main risk of an infinite loop without a break or exit condition in automation scripts?
Why should infinite loops without exit conditions be avoided in automation scripts?
AThey can consume system resources indefinitely, causing performance issues.
BThey always produce syntax errors and fail to run.
CThey automatically stop after 10 minutes to prevent issues.
DThey improve script speed by running continuously without pauses.
Attempts:
2 left
💡 Hint
Think about what happens if a script never stops running.