Bird
0
0

What will be the output of the following commands?

medium📝 Command Output Q13 of 15
Linux CLI - Environment and Configuration
What will be the output of the following commands?
MYVAR="hello"
echo $MYVAR
export MYVAR
bash -c 'echo $MYVAR'
A\n\n
Bhello\n
C\nhello
Dhello\nhello
Step-by-Step Solution
Solution:
  1. Step 1: Understand variable assignment and export

    First, MYVAR is set to "hello" and printed, so first echo outputs "hello". Then MYVAR is exported.
  2. Step 2: Child shell access

    The bash -c 'echo $MYVAR' runs a new shell which inherits exported variables, so it prints "hello" again.
  3. Final Answer:

    hello hello -> Option D
  4. Quick Check:

    Exported variable visible in child shell [OK]
Quick Trick: Exported vars visible in child shells [OK]
Common Mistakes:
  • Assuming unexported vars appear in child shells
  • Confusing echo outputs with command prompts
  • Ignoring export effect on subshells

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes