LFCS · Question #448
Which of the following commands allows an administrator to make a shell variable visible to subshells?
The correct answer is B. export VARIABLE. The export command is used to make a shell variable an environment variable, ensuring that it is inherited and visible to any subshells or child processes.
Question
Options
- Aexport $VARIABLE
- Bexport VARIABLE
- Cset $VARIABLE
- Dset VARIABLE
- Eenv VARIABLE
How the community answered
(48 responses)- A2% (1)
- B94% (45)
- C4% (2)
Why each option
The `export` command is used to make a shell variable an environment variable, ensuring that it is inherited and visible to any subshells or child processes.
`export $VARIABLE` attempts to export the *value* of the variable as a new variable name, which is syntactically incorrect for exporting the variable itself.
The `export VARIABLE` command explicitly marks a shell variable named `VARIABLE` for export, making it an environment variable that will be visible and accessible to any subshells or child processes subsequently created from the current shell.
`set $VARIABLE` would attempt to set shell options or positional parameters based on the variable's value and does not make a variable visible to subshells.
`set VARIABLE` would either set shell options if `VARIABLE` is a valid option or treat `VARIABLE` as a positional parameter, neither of which exports the variable.
`env VARIABLE` would attempt to execute a command named `VARIABLE` within a new environment, or display the current environment, but it does not export a shell variable from the current shell.
Concept tested: Exporting shell variables
Source: https://man7.org/linux/man-pages/man1/bash.1.html
Topics
Community Discussion
No community discussion yet for this question.