What does the code 'while :; do echo hi; done' do?

Study for the OSCP Linux Exam. Use our flashcards and multiple-choice questions to test your skills. Each query comes with detailed hints and explanations to enhance your preparedness. Get ready to conquer the exam!

Multiple Choice

What does the code 'while :; do echo hi; done' do?

Explanation:
In shell scripting, : is a built-in no-op that always returns a successful status. The while loop continues as long as the condition is true, and since : always evaluates to true, the loop never ends. The body prints hi each time, so you get an endless stream of hi until you stop the process. This matches the idea of looping indefinitely while printing hi. It doesn’t exit after a single print, it doesn’t print nothing, and it isn’t limited to a fixed number of iterations.

In shell scripting, : is a built-in no-op that always returns a successful status. The while loop continues as long as the condition is true, and since : always evaluates to true, the loop never ends. The body prints hi each time, so you get an endless stream of hi until you stop the process. This matches the idea of looping indefinitely while printing hi. It doesn’t exit after a single print, it doesn’t print nothing, and it isn’t limited to a fixed number of iterations.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy