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.
Question
Options
- Aenv
- Bset
- Cenv -a
- Decho $ENV
How the community answered
(35 responses)- A9% (3)
- B86% (30)
- C3% (1)
- D3% (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.
`env` lists only the environment variables, which are a subset of all defined shell variables; it does not show local shell variables or functions.
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.
`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.
`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
Community Discussion
No community discussion yet for this question.