LAB_LOCAL=ready is defined but has not been exported.
Confirm it as a variable held by the current Bash.
Which command is appropriate?
Bash set displays shell variables as well as functions. env and printenv show the environment, so they omit an unexported variable.
Detailed explanation
env | grep '^LAB_LOCAL='Incorrect. env lists exported environment variables only.
Incorrect. env lists exported environment variables only.
printenv LAB_LOCALIncorrect. printenv also reads the environment and omits an unexported variable.
Incorrect. printenv also reads the environment and omits an unexported variable.
unset LAB_LOCALIncorrect. unset deletes LAB_LOCAL instead of displaying it.
Incorrect. unset deletes LAB_LOCAL instead of displaying it.
set | grep '^LAB_LOCAL='Correct. set includes variables maintained by the current Bash even when unexported.
Correct. set includes variables maintained by the current Bash even when unexported.
Try it yourself
An example you can run in a temporary verification environment.
LAB_LOCAL=ready
set | grep '^LAB_LOCAL='Expected result
LAB_LOCAL=readyKey points
- Shell variables
- Environment variables
- set versus env
Notes
- Environment: 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.