TMP_MODE is defined in the current Bash.
Make it undefined rather than merely assigning an empty value.
Which command is appropriate?
unset NAME removes a variable definition; NAME= leaves a defined variable whose value is an empty string.
Detailed explanation
TMP_MODE=Incorrect. TMP_MODE= leaves the variable defined with an empty value.
Incorrect. TMP_MODE= leaves the variable defined with an empty value.
export TMP_MODEIncorrect. export changes inheritance attributes and does not undefine the variable.
Incorrect. export changes inheritance attributes and does not undefine the variable.
unset TMP_MODECorrect. unset removes TMP_MODE from the current shell.
Correct. unset removes TMP_MODE from the current shell.
set TMP_MODEIncorrect. set does not remove the named variable.
Incorrect. set does not remove the named variable.
Try it yourself
An example you can run in a temporary verification environment.
bash --noprofile --norc -c 'TMP_MODE=test; unset TMP_MODE; if [[ -v TMP_MODE ]]; then echo defined; else echo undefined; fi'Expected result
undefinedKey points
- unset removes a definition
- Empty and undefined differ
- [[ -v NAME ]]
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.