Bird
0
0

What will be the output of the following commands?

medium📝 Command Output Q4 of 15
Linux CLI - Environment and Configuration
What will be the output of the following commands?
MYVAR=hello
export MYVAR
bash -c 'echo $MYVAR'
A(no output — empty line)
Bhello
CMYVAR
Dbash: MYVAR: command not found
Step-by-Step Solution
Solution:
  1. Step 1: Understand variable export and subshell

    Assigning MYVAR=hello and exporting it makes it available to child shells.
  2. Step 2: Check the subshell echo

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

    hello -> Option B
  4. Quick Check:

    exported variable visible in subshell = hello [OK]
Quick Trick: Exported variables appear in child shells [OK]
Common Mistakes:
  • Assuming variable is empty in subshell
  • Confusing variable name with value
  • Expecting error from echo

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes