Bird
0
0

What does the following bash loop do?

easy🧠 Conceptual Q11 of 15
Bash Scripting - Loops
What does the following bash loop do?
for file in *; do echo "$file"; done
AIt runs the echo command once without any output.
BIt deletes all files in the current folder.
CIt lists only directories in the current folder.
DIt prints the names of all files and directories in the current folder.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the loop variable and pattern

    The loop uses * which matches all files and directories in the current folder.
  2. Step 2: Analyze the command inside the loop

    Each matched item is stored in file and printed with echo.
  3. Final Answer:

    It prints the names of all files and directories in the current folder. -> Option D
  4. Quick Check:

    Loop over * prints all names [OK]
Quick Trick: Remember * matches all files and folders [OK]
Common Mistakes:
MISTAKES
  • Thinking * matches only files, not directories
  • Assuming the loop deletes files
  • Believing echo runs only once

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes