Bird
0
0

Given the commands below, what will be the output?

medium📝 Command Output Q5 of 15
Linux CLI - Environment and Configuration
Given the commands below, what will be the output?
export VAR1=foo
VAR2=bar
bash -c 'echo $VAR1 $VAR2'
Afoo
Bfoo bar
C bar
D(no output — empty line)
Step-by-Step Solution
Solution:
  1. Step 1: Identify exported and non-exported variables

    VAR1 is exported, so it is visible in the child shell. VAR2 is not exported, so it is not visible.
  2. Step 2: Analyze the echo output in the child shell

    The child shell prints $VAR1 as foo and $VAR2 as empty, resulting in foo .
  3. Final Answer:

    foo -> Option A
  4. Quick Check:

    Only exported variables visible in subshell = foo [OK]
Quick Trick: Only exported vars pass to child shells [OK]
Common Mistakes:
  • Expecting non-exported vars in subshell
  • Confusing export with assignment
  • Assuming both variables print

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes