Bird
0
0

Consider this script: ```bash export VAR1=foo VAR2=bar bash -c 'echo "$VAR1 $VAR2"' ``` What is the output?

medium📝 Predict Output Q5 of 15
Bash Scripting - Variables
Consider this script: ```bash export VAR1=foo VAR2=bar bash -c 'echo "$VAR1 $VAR2"' ``` What is the output?
Afoo bar
Bfoo
C bar
DVAR1 VAR2
Step-by-Step Solution
Solution:
  1. Step 1: Understand export effect

    'VAR1' is exported, so it is available in the child bash process. 'VAR2' is not exported, so it is not available.
  2. Step 2: Analyze the child bash command

    The child bash prints the values of VAR1 and VAR2. VAR1 prints 'foo', VAR2 is empty, so output is 'foo '.
  3. Final Answer:

    foo -> Option B
  4. Quick Check:

    Only exported variables appear in child processes [OK]
Quick Trick: Only exported variables pass to child shells [OK]
Common Mistakes:
MISTAKES
  • Assuming all variables pass to child processes
  • Confusing export with assignment
  • Expecting VAR2 to print 'bar'

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes