Bird
0
0

What will be the output of this script?

medium📝 Command Output Q13 of 15
Bash Scripting - Variables
What will be the output of this script?
name="Alice"
echo "Hello, $name!"
name="Bob"
echo "Hello again, $name!"
AHello, Alice! Hello again, Bob!
BHello, Alice! Hello again, Alice!
CHello, $name! Hello again, $name!
DHello, Bob! Hello again, Bob!
Step-by-Step Solution
Solution:
  1. Step 1: Follow variable assignment and usage

    The variable 'name' is first set to "Alice" and used in the first echo, printing "Hello, Alice!".
  2. Step 2: Update variable and print again

    Then 'name' is changed to "Bob" and echoed again, printing "Hello again, Bob!".
  3. Final Answer:

    Hello, Alice! Hello again, Bob! -> Option A
  4. Quick Check:

    Variable updates change output = A [OK]
Quick Trick: Variable value changes affect later output [OK]
Common Mistakes:
MISTAKES
  • Assuming variable value stays the same after change
  • Printing variable name literally without $
  • Confusing variable assignment with comparison

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes