Recall & Review
beginner
What is an infinite loop in bash scripting?
An infinite loop is a loop that never stops running because its exit condition is never met or it has no exit condition.
Click to reveal answer
beginner
How do you write a simple infinite loop using
while in bash?You can write it as:
while true; do # commands doneThis runs the commands forever until you stop it.
Click to reveal answer
beginner
What command can you use to stop an infinite loop running in the terminal?
Press Ctrl + C to send an interrupt signal that stops the running infinite loop.
Click to reveal answer
intermediate
Why might infinite loops be useful in scripting?
They are useful for tasks that need to run continuously, like monitoring a system or waiting for events.
Click to reveal answer
intermediate
Show an example of an infinite loop using
for in bash.Example:
for (( ; ; )); do echo "Looping forever" sleep 1 doneThis loops forever because there are no conditions.
Click to reveal answer
Which of these is a correct way to write an infinite loop in bash?
✗ Incorrect
Option A runs forever because 'true' is always true. Option B never runs. Option C runs once, not infinite. Option D is a single condition, not a loop.
How do you stop a running infinite loop in the terminal?
✗ Incorrect
Ctrl + C sends an interrupt signal to stop the loop immediately. Ctrl + Z pauses the process but does not stop it.
What will this loop do?
for (( ; ; )); do echo "Hello"; done
✗ Incorrect
The for loop has no conditions, so it runs forever printing 'Hello'.
Why should you be careful when writing infinite loops?
✗ Incorrect
Infinite loops can use up CPU and memory, causing your system to slow down or crash if not managed.
Which command inside an infinite loop can help avoid high CPU usage?
✗ Incorrect
Using 'sleep 1' pauses the loop for 1 second each time, reducing CPU load.
Explain what an infinite loop is and how you can create one in bash.
Think about loops that never stop running.
You got /3 concepts.
Describe how to safely stop an infinite loop running in your terminal and why you might want to use infinite loops.
Consider both stopping and using infinite loops.
You got /3 concepts.