LFCS · Question #115
Which command makes the shell variable named VARIABLE visible to subshells?
The correct answer is B. export VARIABLE. The export command makes a shell variable visible and accessible to subshells or child processes.
Question
Options
- Aexport $VARIABLE
- Bexport VARIABLE
- Cset $VARIABLE
- Dset VARIABLE
- Eenv VARIABLE
How the community answered
(17 responses)- A6% (1)
- B88% (15)
- E6% (1)
Why each option
The `export` command makes a shell variable visible and accessible to subshells or child processes.
`export $VARIABLE` is syntactically incorrect for exporting a variable; it attempts to use the *value* of the variable as the name of the variable to be exported, which will fail or produce an unintended result.
The `export VARIABLE` command marks the specified shell variable to be placed in the environment of any child processes that are subsequently created from the current shell, thus making it visible to subshells.
`set $VARIABLE` sets the shell's positional parameters to the words contained in the variable's value and does not export variables to subshells.
`set VARIABLE` simply displays shell variables or sets shell options, it does not export variables to subshells.
`env VARIABLE` (if VARIABLE is a value) or `env -i VARIABLE=VALUE command` runs a command with a modified environment or displays environment variables, but it does not export the variable from the current shell for general subshell inheritance.
Concept tested: Shell variable export (`export`)
Source: https://man7.org/linux/man-pages/man1/bash.1.html
Topics
Community Discussion
No community discussion yet for this question.