Which of the following commands lists all defined variables and functions within Bash?
Click on the arrows to vote for the correct answer
A. B. C. D.B
The correct answer to the question is B. set
.
Explanation: The set
command is used to set or unset shell options and positional parameters, and to display the current configuration of the shell. When used without any arguments, it displays all defined variables and functions within the Bash shell.
For example, if you run the set
command in a Bash shell, you will see output similar to the following:
makefileBASH=/bin/bash BASHOPTS=checkwinsize:cmdhist:expand_aliases:extquote:force_fignore:histappend:interactive_comments:progcomp:promptvars:sourcepath BASH_ALIASES=() BASH_ARGC=() BASH_ARGV=() BASH_CMDS=() ...
This output shows all the environment variables and shell options that are currently defined in the Bash shell.
Option A, env
, lists the environment variables, but it does not display functions or shell options.
Option C, env -a
, lists all environment variables, including those that are not exported to child processes, but it does not display functions or shell options.
Option D, echo $ENV
, will only print the value of the ENV
environment variable, if it is set. It will not display any functions or shell options.
Therefore, the correct answer is B, set
, as it displays all defined variables and functions within the Bash shell.