nerdexam
CompTIA

LX0-104 · 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 in a shell to mark a variable so that it becomes visible in the environment of any subshells or child processes that are subsequently launched.

Shells, Scripting and Data Management

Question

Which of the following commands allows an administrator to make a shell variable visible to subshells?

Options

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

How the community answered

(51 responses)
  • B
    88% (45)
  • C
    4% (2)
  • D
    6% (3)
  • E
    2% (1)

Why each option

The `export` command is used in a shell to mark a variable so that it becomes visible in the environment of any subshells or child processes that are subsequently launched.

Aexport $VARIABLE

`export $VARIABLE` attempts to export the *value* of the variable as a new variable name, which is syntactically incorrect and not the way to make a variable visible to subshells.

Bexport VARIABLECorrect

The `export` command, when followed by a variable name without the dollar sign, marks that variable for export to the environment of subsequent child processes. This makes the variable accessible to any subshells launched from the current shell.

Cset $VARIABLE

The `set` command is used to display or modify shell options and positional parameters, or to list shell variables, but it does not export variables to subshells.

Dset VARIABLE

Similar to choice C, `set VARIABLE` would just display the variable's value if it exists or define a positional parameter, and does not make the variable visible to subshells.

Eenv VARIABLE

The `env` command displays the current environment or executes a command in a modified environment; `env VARIABLE` would attempt to run `VARIABLE` as a command with an empty environment, which is not the correct usage to export a variable.

Concept tested: Shell variable export and subshell environment

Source: https://www.gnu.org/software/bash/manual/bash.html#index-export

Topics

#shell variables#export command#subshells#environment variables

Community Discussion

No community discussion yet for this question.

Full LX0-104 Practice