Simple debugging approach – echoing values during script execution
The first thing you will learn when using Bash is how to regularly use the echo
command when running any script. This approach is simple as it gives us an opportunity to follow the workflow of the script and to print the values of the variables as they are in different points of the script. Being able to understand both those things is going to help us to follow all the inputs to our script and to see how they transform into outputs that we expect.
Getting ready
In this recipe, we are going to deal with simple ways we can make our script help us understand what is happening during its run. There are three ways we can use this simple method.
The first thing we can do is use the echo
command in every place in the script that we think is helpful. As an example, take a look at one of the scripts from previous chapters (funcglobal.sh
) that is already pretty verbose: