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.
envIncorrect. env shows the process environment and omits unexported LOCAL_ONLY.
export -pIncorrect. export -p lists names with the export attribute.
unsetIncorrect. 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 / 現在のシェル状態のみ
- Use disposable shell sessions and harmless commands for experiments.
- Shell behavior can depend on Bash options and distribution defaults.
Foundation review
Place the operation
The shell's complete state is broader than the environment passed to external commands.
Check the side effect
Define one local variable and one exported variable, then compare the three listings.