Which command makes the shell variable named VARIABLE visible to subshells?
Click on the arrows to vote for the correct answer
A. B. C. D. E.B
The correct answer is B. export VARIABLE.
When a shell variable is defined in a parent shell, it is not automatically visible to any subshells that may be spawned. The export
command is used to make the shell variable visible to subshells. The syntax for exporting a variable is as follows:
javascriptexport VARIABLE
This will make the value of the shell variable named VARIABLE
available to any subshells that are spawned from the current shell. It is important to note that the variable must first be defined in the current shell before it can be exported.
Answer A, export $VARIABLE
, is incorrect because the $
character is not needed when specifying the name of the variable to be exported. The $
character is only used to expand the value of the variable when it is referenced.
Answer C, set $VARIABLE
, is incorrect because the set
command is used to set shell options or positional parameters, not to export variables.
Answer D, set VARIABLE
, is incorrect for the same reason as option C.
Answer E, env VARIABLE
, is incorrect because the env
command is used to run a command in a modified environment, not to export variables.