nerdexam
CompTIA

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.

Shells, Scripting and Data Management

Question

Which command makes the shell variable named VARIABLE visible to subshells?

Options

  • Aexport $VARIABLE
  • Bexport VARIABLE
  • Cset $VARIABLE
  • Dset VARIABLE
  • Eenv VARIABLE

How the community answered

(47 responses)
  • B
    96% (45)
  • C
    2% (1)
  • E
    2% (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.

Aexport $VARIABLE

export $VARIABLE attempts to export the value of the variable as a command, which is incorrect syntax for exporting a variable itself.

Bexport VARIABLECorrect

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.

Cset $VARIABLE

set $VARIABLE would set shell options or positional parameters based on the variable's value, not export the variable.

Dset VARIABLE

set VARIABLE is not a valid command to make a variable visible to subshells; set primarily controls shell options and positional parameters.

Eenv VARIABLE

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

#shell variables#export command#subshells

Community Discussion

No community discussion yet for this question.

Full LX0-104 Practice