LX0-104 · Question #91
Which of the following commands lists all defined variables and functions within Bash?
The correct answer is B. set. The set command in Bash, when invoked without arguments, displays all shell variables, environment variables, and shell functions. This provides a comprehensive overview of the current shell's state.
Question
Options
- Aenv
- Bset
- Cenv -a
- Decho $ENV
How the community answered
(21 responses)- B95% (20)
- D5% (1)
Why each option
The `set` command in Bash, when invoked without arguments, displays all shell variables, environment variables, and shell functions. This provides a comprehensive overview of the current shell's state.
The `env` command primarily lists environment variables, not all shell variables or shell functions.
The `set` command without any options lists all shell variables, including environment variables, and all defined shell functions for the current Bash session. This makes it the most comprehensive command for inspecting the entire state of the shell regarding variables and functions.
`env -a` is not a standard or valid option for the `env` command; `env` only lists environment variables.
`echo $ENV` would print the value of the `ENV` variable if it is set, which typically points to a shell initialization file, not a list of all variables and functions.
Concept tested: Bash shell - variable and function listing
Source: https://www.gnu.org/software/bash/manual/bash.html#The-Set-Builtin
Topics
Community Discussion
No community discussion yet for this question.