LOCAL_ONLY=secret is set in Bash but has not been exported.
List definitions that include this shell variable, not only environment variables.
Which command is appropriate?
Bash set displays the current shell state, including variables that do not have the export attribute. env and export -p focus on exported names.
Detailed explanation
setCorrect. set displays shell variables and functions, including unexported variables.
Correct. set displays shell variables and functions, including unexported variables.
envIncorrect. env shows the process environment and omits unexported LOCAL_ONLY.
Incorrect. env shows the process environment and omits unexported LOCAL_ONLY.
export -pIncorrect. export -p lists names with the export attribute.
Incorrect. export -p lists names with the export attribute.
unsetIncorrect. unset removes variables rather than listing definitions.
Incorrect. unset removes variables rather than listing definitions.
Try it yourself
An example you can run in a temporary verification environment.
LOCAL_ONLY=secret; set | grep '^LOCAL_ONLY='Expected result
LOCAL_ONLY=secretKey points
- set lists shell variables
- env lists the environment
- export -p lists exported names
Notes
- Environment: Bash 5.x / 現在のシェル状態のみ
- 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.