Concept Flow - Unsetting variables (unset)
Variable is set
Call unset command
Variable is removed
Variable no longer exists
The flow shows a variable initially set, then the unset command removes it, so it no longer exists.
name="Alice"
echo $name
unset name
echo $name| Step | Command | Variable 'name' Value | Output |
|---|---|---|---|
| 1 | name="Alice" | Alice | |
| 2 | echo $name | Alice | Alice |
| 3 | unset name | unset (no value) | |
| 4 | echo $name | unset (no value) |
| Variable | Start | After Step 1 | After Step 3 | Final |
|---|---|---|---|---|
| name | unset | Alice | unset | unset |
unset variable_name - Removes the variable completely - After unset, variable has no value - echo prints nothing if variable unset - Useful to clear variables in scripts