First, MYVAR is set to "hello" and printed, so first echo outputs "hello". Then MYVAR is exported.
Step 2: Child shell access
The bash -c 'echo $MYVAR' runs a new shell which inherits exported variables, so it prints "hello" again.
Final Answer:
hello
hello -> Option D
Quick Check:
Exported variable visible in child shell [OK]
Hint: 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
4. Identify the error in this script snippet:
export MYVAR
MYVAR="world"
echo $MYVAR
medium
A. echo command is missing quotes
B. export command syntax is wrong
C. MYVAR is exported before assignment, so child shells get empty value
D. No error, script works fine
Solution
Step 1: Analyze export before assignment
Exporting MYVAR before assigning means MYVAR is empty when exported.
Step 2: Effect on variable value
Assigning MYVAR after export does not update the exported environment variable for child processes.
Final Answer:
MYVAR is exported before assignment, so child shells get empty value -> Option C
Quick Check:
Export before assignment exports empty value [OK]
Hint: Assign before export to share correct value [OK]
Common Mistakes:
Exporting before assigning value
Thinking export syntax is wrong
Assuming echo needs quotes always
5. You want to set a variable CONFIG_PATH to /etc/config and ensure it is available to all scripts run from your current shell session and its children. Which sequence of commands achieves this correctly?
hard
A. CONFIG_PATH=/etc/config\nexport CONFIG_PATH
B. export CONFIG_PATH=/etc/config
C. export CONFIG_PATH\nCONFIG_PATH=/etc/config
D. CONFIG_PATH=/etc/config
Solution
Step 1: Assign variable before export
Assigning CONFIG_PATH=/etc/config sets the value in the current shell.
Step 2: Export variable after assignment
Running export CONFIG_PATH marks it for child processes with the assigned value.
Step 3: Check other options
export CONFIG_PATH=/etc/config works but is less clear; export CONFIG_PATH\nCONFIG_PATH=/etc/config exports before assignment (wrong); CONFIG_PATH=/etc/config does not export.
Final Answer:
CONFIG_PATH=/etc/config
export CONFIG_PATH -> Option A
Quick Check:
Assign then export to share variable [OK]
Hint: Assign first, then export to share variable [OK]
Common Mistakes:
Exporting before assigning value
Not exporting variable at all
Assuming single export with assignment is always best
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.