Bird
0
0

Why does this script fail?

medium📝 Debug Q7 of 15
Bash Scripting - Loops
Why does this script fail?
for i in {1..5}; do echo i; done
AVariable i is not expanded with $
BBrace expansion is incorrect
CMissing 'done' keyword
DSyntax error in for loop
Step-by-Step Solution
Solution:
  1. Step 1: Check variable usage in echo

    Echo prints the literal string 'i' because $ is missing before i.
  2. Step 2: Confirm brace expansion and loop syntax

    Brace expansion and loop syntax are correct, so error is variable expansion.
  3. Final Answer:

    Variable i is not expanded with $ -> Option A
  4. Quick Check:

    Use $ to expand variables in echo = Variable i is not expanded with $ [OK]
Quick Trick: Always use $ before variable names to print their values [OK]
Common Mistakes:
MISTAKES
  • Forgetting $ before variable in echo
  • Assuming brace expansion is wrong
  • Missing loop keywords

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes