nerdexam
LPI

102-500 · Question #189

Which of the following is the best way to list all defined shell variables?

The correct answer is B. set. set lists all shell variables - both environment variables and shell-local variables (including functions) - making it the most complete option for seeing everything defined in the current shell session. Why the distractors are wrong: A. env - shows only exported environment…

Shells and Shell Scripting

Question

Which of the following is the best way to list all defined shell variables?

Options

  • Aenv
  • Bset
  • Cenv -a
  • Decho $ENV

How the community answered

(25 responses)
  • A
    4% (1)
  • B
    84% (21)
  • C
    8% (2)
  • D
    4% (1)

Explanation

set lists all shell variables - both environment variables and shell-local variables (including functions) - making it the most complete option for seeing everything defined in the current shell session.

Why the distractors are wrong:

  • A. env - shows only exported environment variables, missing shell-local variables that haven't been exported with export.
  • C. env -a - not a standard/portable flag; env doesn't accept -a in most implementations, and even where it does it still only covers environment variables.
  • D. echo $ENV - prints the value of a single variable named ENV (typically the path to the shell's config file), not a list of variables.

Memory tip: Think "Set = Sees everything" - set is the most comprehensive command because it operates at the shell level, while env only sees what's been promoted to the environment.

Topics

#shell variables#set command#env command#variable scope

Community Discussion

No community discussion yet for this question.

Full 102-500 Practice