Bird
0
0

What will be the output of this script?

medium📝 Command Output Q4 of 15
Bash Scripting - Variables
What will be the output of this script?
VAR=10
readonly VAR
VAR=20
echo $VAR
A20
B10
CError: VAR is readonly
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Assign and mark VAR as readonly

    VAR is set to 10 and then made readonly.
  2. Step 2: Attempt to change VAR to 20

    This assignment fails with an error on stderr; VAR remains 10.
  3. Final Answer:

    10 -> Option B
  4. Quick Check:

    Readonly variable value unchanged = 10 [OK]
Quick Trick: Readonly variables keep original value despite reassignment [OK]
Common Mistakes:
MISTAKES
  • Expecting reassignment to change value
  • Thinking error message is printed
  • Assuming variable becomes empty

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes