Performing operations on variables
Variables are great since they can hold any value that we can think of. Often, we need more than just holding a value inside a variable. In this recipe, we are going to deal with a lot of different things that we can do to a variable, sometimes changing it and sometimes completely replacing it.
Getting ready
In order to be able to change variables, you will need to understand one simple concept. bash
cannot change the variable itself; we are going to mention this a little later, but if you need to change something in a variable, you will have to reassign it.
How to do it…
There is a lot of things that can be done to a variable. Sometimes, we want to know more about what it contains; sometimes, we need to change something in order to use it later; or, we may simply want to know if the variable even has a value.
In this recipe, we are going to use the command line a lot since it makes explaining things much easier.
Before...