Make DEBUG_TOKEN undefined in the current Bash rather than leaving an empty variable.
Which command is appropriate?
unset NAME removes the variable definition. NAME= leaves a defined variable with an empty value, and export -n changes only the export attribute.
Detailed explanation
unset DEBUG_TOKENCorrect. unset DEBUG_TOKEN removes the definition.
Correct. unset DEBUG_TOKEN removes the definition.
DEBUG_TOKEN=Incorrect. DEBUG_TOKEN= leaves the variable defined with an empty value.
Incorrect. DEBUG_TOKEN= leaves the variable defined with an empty value.
export -n DEBUG_TOKENIncorrect. export -n removes export status but not the variable itself.
Incorrect. export -n removes export status but not the variable itself.
set DEBUG_TOKENIncorrect. set displays or manipulates shell options and variables; it does not unset this name.
Incorrect. set displays or manipulates shell options and variables; it does not unset this name.
Try it yourself
An example you can run in a temporary verification environment.
DEBUG_TOKEN=value; unset DEBUG_TOKEN; if [[ -v DEBUG_TOKEN ]]; then echo defined; else echo unset; fiExpected result
unsetKey points
- unset removes definition
- NAME= is an empty string
- export -n changes an attribute
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.