102-500 · Question #14
Which command makes the shell variable named VARIABLE visible to subshells?
The correct answer is E. export VARIABLE. export VARIABLE (E) makes a shell variable part of the environment, which is inherited by any child processes (subshells) spawned from the current shell. The variable name is passed to export - not its value - so no $ prefix is used. Why the distractors fail: A (export…
Question
Options
- Aexport $VARIABLE
- Benv VARIABLE
- Cset $VARIABLE
- Dset VARIABLE
- Eexport VARIABLE
How the community answered
(49 responses)- A2% (1)
- B10% (5)
- C2% (1)
- D4% (2)
- E82% (40)
Explanation
export VARIABLE (E) makes a shell variable part of the environment, which is inherited by any child processes (subshells) spawned from the current shell. The variable name is passed to export - not its value - so no $ prefix is used.
Why the distractors fail:
- A (
export $VARIABLE) - the$causes the shell to expandVARIABLEto its value first, so you'd be exporting that value as a variable name, not the variable itself. - B (
env VARIABLE) -envwithout an assignment (VAR=val) just prints the environment or runs a command; it doesn't export anything. - C (
set $VARIABLE) -setwith a$-prefixed argument sets positional parameters ($1,$2, …), not named variables. - D (
set VARIABLE) -setconfigures shell options (e.g.,set -e); it doesn't create or export named variables.
Memory tip: Think "export the name, not the value" - just like you'd label a box before shipping it, you write the variable's name (VARIABLE), not what's inside it ($VARIABLE).
Topics
Community Discussion
No community discussion yet for this question.