September 2018
Beginner
186 pages
4h 30m
English
If you want to assign a variable an empty value, you can do so by leaving the right side of an assignment to the variable blank:
$ system=
However, the variable name still appears in the list of variables, it just has an empty value:
bash$ declare -p system declare -- system=""
The system variable is defined, but empty. POSIX shell script actually does not make much of a distinction between these two states. It's more common to test whether a variable is empty than it is to check whether it's defined:
#!/bin/bash
# If the 'system' variable is not empty, print its value to the user
if [[ -n $system ]] ; then
printf 'The "system" variable is: %s\n' "$system"
fi
You can actually remove a variable with unset:
$ unset -v system ...
Read now
Unlock full access