What is a variable?
Variables are a standard building block used in many (if not all) programming and scripting languages. Variables allow us to store information, so we can reference and use it later, often multiple times. We can, for example, use the textvariable
variable to store the sentence This text is contained in the variable
. In this case, the variable name of textvariable
is referred to as the key, and the content of the variable (the text) is referred to as the value, in the key-value pair that makes up the variable.
In our program, we always reference the textvariable
variable when we need the text. This might be a bit abstract now, but we're confident that after seeing the examples in the rest of the chapter, the usefulness of variables will become clear.
We've actually already seen Bash variables in use. Remember, in Chapter 4, The Linux Filesystem, we looked at both the BASH_VERSION
and PATH
variables. Let's see how we can use variables in shell scripting. We'll take our hello...