nerdexam
CompTIA

LX0-104 · Question #443

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

The correct answer is B. set. The set command without any arguments is the most comprehensive way to list all defined shell variables, including environment variables, local variables, and shell functions.

Shells, Scripting and Data Management

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

(35 responses)
  • A
    9% (3)
  • B
    86% (30)
  • C
    3% (1)
  • D
    3% (1)

Why each option

The `set` command without any arguments is the most comprehensive way to list all defined shell variables, including environment variables, local variables, and shell functions.

Aenv

`env` lists only the environment variables, which are a subset of all defined shell variables; it does not show local shell variables or functions.

BsetCorrect

The `set` command, when executed without any arguments, displays all shell variables (local and environment), shell functions, and shell options that are currently set in the shell's environment. This provides the most complete overview of the shell's state.

Cenv -a

`env -a` is not a standard or valid option for the `env` command; `env` typically doesn't have a `-a` option for listing all variables.

Decho $ENV

`echo $ENV` displays the value of the `ENV` variable (if it's set), which typically points to a startup script, not a listing of all variables.

Concept tested: Listing shell variables

Source: https://linux.die.net/man/1/set

Topics

#shell variables#set command#environment variables

Community Discussion

No community discussion yet for this question.

Full LX0-104 Practice