A variable is a name that holds a value. Your shell keeps it until you close the terminal.
Set a variable
learner@tidepool:~$ RELEASE=v2.4.0There must be no spaces around =. With spaces, the shell splits the line into words, and the first word becomes a command:
learner@tidepool:~$ RELEASE = v2.4.0
bash: RELEASE: command not foundA name has letters, numbers and _. It cannot start with a number. Many people use uppercase names for the variables that they set.
Read a variable: $NAME
Put $ before the name. The shell changes $NAME to the value before the command starts:
learner@tidepool:~$ echo $RELEASE
v2.4.0This is the same idea as wildcards: the shell changes the line first, then the program starts.
A variable that is not set
A name that has no value gives an empty result, with no error. A typing error in a name is easy to miss:
learner@tidepool:~$ echo $RELASE
Change and remove
Set the variable again to change its value. unset removes it:
learner@tidepool:~$ RELEASE=v2.5.0
learner@tidepool:~$ unset RELEASEA shell variable exists only in the shell where you set it. A new terminal does not have it.