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?
MYVAR=hello
readonly MYVAR
MYVAR=world
echo $MYVAR
Aworld
BError: cannot modify readonly variable
CSyntax error
Dhello
Step-by-Step Solution
Solution:
  1. Step 1: Understand the script flow

    The variable MYVAR is assigned "hello" and then made readonly. The script then tries to change it to "world".
  2. Step 2: Predict the behavior when modifying a readonly variable

    Bash will produce an error message when trying to assign a new value to a readonly variable, but the script will continue and the value of MYVAR remains "hello". The echo command outputs the original value.
  3. Final Answer:

    hello -> Option D
  4. Quick Check:

    Readonly variable value remains unchanged; echo prints original value [OK]
Quick Trick: Changing readonly variable causes error message but value unchanged [OK]
Common Mistakes:
MISTAKES
  • Assuming variable changes silently
  • Expecting syntax error instead of runtime error
  • Thinking echo prints new value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes