Bird
0
0

What will be the output of the following Bash commands?

medium📝 Command Output Q4 of 15
Linux CLI - Linux Basics and Terminal
What will be the output of the following Bash commands?
count=3
while [ $count -gt 0 ]; do
  echo $count
  ((count--))
done
A3 2 1
B1 2 3
C3 2 1 0
D0 1 2 3
Step-by-Step Solution
Solution:
  1. Step 1: Understand the loop and condition

    The loop starts with count=3 and runs while count is greater than 0. It prints count then decreases it by 1 each time.
  2. Step 2: Trace the output values

    First iteration: prints 3, count becomes 2
    Second: prints 2, count becomes 1
    Third: prints 1, count becomes 0
    Loop ends because 0 is not greater than 0.
  3. Final Answer:

    3 2 1 -> Option A
  4. Quick Check:

    Loop output sequence = 3 2 1 [OK]
Quick Trick: Loops run while condition is true; count decreases each time [OK]
Common Mistakes:
  • Including 0 in output
  • Printing in wrong order
  • Misunderstanding loop condition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes