Understanding Common Scripting Errors
The most important step in debugging is understanding the common errors that could cause your scripts to either outright fail, or to give you incorrect results. Let’s look at a few examples.
Not Enough Quoting
You can have a few different problems if you don’t surround variable names with quotes. Here are some examples.
Filenames with Blank Spaces
For this demo, I’ve moved into an empty directory in order to keep the files I’ll be creating separate from the files in my main home directory. I want to create some files with a timestamp in the filename. To do that, I’ll use the date
command, without any option switches.
First, I’ll create a file from the command-line using touch
:
donnie@fedora:~/quoting_demo$ touch somefile_$(date).txt
donnie@fedora:~/quoting_demo$
Okay, let’s look at the file:
donnie@fedora:~/quoting_demo$ ls -l
total 0
-rw-r--r--. 1 donnie donnie...