What happens if you make a for loop without 'in blahblah'?

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 happens if you make a for loop without 'in blahblah'?

Explanation:
When you write a for loop without the in part, Bash takes the shell’s positional parameters (the arguments given to the script or function) as the list to loop over. Each iteration assigns one argument to the loop variable, so the loop processes every parameter you passed. For example, using: for item; do echo "$item"; done will print each argument you supplied when running the script. If you run the script with alpha, beta, gamma, you’ll see those three values printed in order. If there are no arguments, the loop has nothing to iterate over, so it does nothing. This matches the idea that it uses the list of arguments passed to the command as the items to loop over. The other options describe different sources (an infinite loop, files in the directory, or a predefined number list) that aren’t what happens when the in clause is omitted.

When you write a for loop without the in part, Bash takes the shell’s positional parameters (the arguments given to the script or function) as the list to loop over. Each iteration assigns one argument to the loop variable, so the loop processes every parameter you passed.

For example, using: for item; do echo "$item"; done will print each argument you supplied when running the script. If you run the script with alpha, beta, gamma, you’ll see those three values printed in order. If there are no arguments, the loop has nothing to iterate over, so it does nothing.

This matches the idea that it uses the list of arguments passed to the command as the items to loop over. The other options describe different sources (an infinite loop, files in the directory, or a predefined number list) that aren’t what happens when the in clause is omitted.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy