LX0-104 · Question #115
Which command makes the shell variable named VARIABLE visible to subshells?
The correct answer is B. export VARIABLE. The export command is used to mark a shell variable so that it will be passed into the environment of child processes or subshells.
Question
Options
- Aexport $VARIABLE
- Bexport VARIABLE
- Cset $VARIABLE
- Dset VARIABLE
- Eenv VARIABLE
How the community answered
(47 responses)- B96% (45)
- C2% (1)
- E2% (1)
Why each option
The export command is used to mark a shell variable so that it will be passed into the environment of child processes or subshells.
export $VARIABLE attempts to export the value of the variable as a command, which is incorrect syntax for exporting a variable itself.
The export command, when followed by a variable name, adds that variable to the environment of current shell. Any subshells or child processes subsequently started by the current shell will inherit this exported variable and its value.
set $VARIABLE would set shell options or positional parameters based on the variable's value, not export the variable.
set VARIABLE is not a valid command to make a variable visible to subshells; set primarily controls shell options and positional parameters.
env VARIABLE would print environment variables or run a command with a modified environment, but it does not export a variable from the current shell to future subshells.
Concept tested: Exporting shell variables to subshells
Source: https://linux.die.net/man/1/export
Topics
Community Discussion
No community discussion yet for this question.