LFCS · 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 effective tool to display all shell variables, including environment variables, local variables, and shell functions.
Question
Options
- Aenv
- Bset
- Cenv -a
- Decho $ENV
How the community answered
(38 responses)- A5% (2)
- B89% (34)
- C3% (1)
- D3% (1)
Why each option
The `set` command without any arguments is the most effective tool to display all shell variables, including environment variables, local variables, and shell functions.
`env` displays only environment variables, not local shell variables or shell functions.
The `set` command, when executed without any arguments, displays all defined shell variables, including local variables set within the current shell, environment variables inherited or exported, and shell functions.
`env -a` is not a standard or valid option for the `env` command in most shell implementations.
`echo $ENV` will only display the value of a specific variable named `ENV`, which is not a standard mechanism for listing all shell variables.
Concept tested: Listing shell variables
Source: https://man7.org/linux/man-pages/man1/bash.1.html
Topics
Community Discussion
No community discussion yet for this question.