nerdexam
LPI

102-500 · Question #14

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

The correct answer is E. export VARIABLE. export VARIABLE (E) makes a shell variable part of the environment, which is inherited by any child processes (subshells) spawned from the current shell. The variable name is passed to export - not its value - so no $ prefix is used. Why the distractors fail: A (export…

Shells and Shell Scripting

Question

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

Options

  • Aexport $VARIABLE
  • Benv VARIABLE
  • Cset $VARIABLE
  • Dset VARIABLE
  • Eexport VARIABLE

How the community answered

(49 responses)
  • A
    2% (1)
  • B
    10% (5)
  • C
    2% (1)
  • D
    4% (2)
  • E
    82% (40)

Explanation

export VARIABLE (E) makes a shell variable part of the environment, which is inherited by any child processes (subshells) spawned from the current shell. The variable name is passed to export - not its value - so no $ prefix is used.

Why the distractors fail:

  • A (export $VARIABLE) - the $ causes the shell to expand VARIABLE to its value first, so you'd be exporting that value as a variable name, not the variable itself.
  • B (env VARIABLE) - env without an assignment (VAR=val) just prints the environment or runs a command; it doesn't export anything.
  • C (set $VARIABLE) - set with a $-prefixed argument sets positional parameters ($1, $2, …), not named variables.
  • D (set VARIABLE) - set configures shell options (e.g., set -e); it doesn't create or export named variables.

Memory tip: Think "export the name, not the value" - just like you'd label a box before shipping it, you write the variable's name (VARIABLE), not what's inside it ($VARIABLE).

Topics

#export command#environment variables#shell variables#subshells

Community Discussion

No community discussion yet for this question.

Full 102-500 Practice