Inspect shell variables and function definitions in the current Bash.
Do not limit the output to exported environment variables.
Which no-argument builtin is appropriate?
set without arguments lists the current shell variables and functions; env and export -p have narrower scopes.
Detailed explanation
envIncorrect. env shows the command environment and omits unexported variables and functions.
Incorrect. env shows the command environment and omits unexported variables and functions.
export -pIncorrect. export -p lists only names marked for export.
Incorrect. export -p lists only names marked for export.
setCorrect. set lists shell variables and function definitions.
Correct. set lists shell variables and function definitions.
unsetIncorrect. unset removes definitions rather than listing them.
Incorrect. unset removes definitions rather than listing them.
Try it yourself
An example you can run in a temporary verification environment.
bash --noprofile --norc -c 'LOCAL_ONLY=value; demo(){ :; }; set' | grep -E '^(LOCAL_ONLY=value|demo \(\))'Expected result
LOCAL_ONLY=valueとdemo ()の関数定義Key points
- set shows shell state
- env shows environment
- export -p shows exported names
Notes
- Environment: GNU Bash 5.2 / 一時シェル
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.