When in doubt – quote!

Having established that variables are a type of parameter, we should always keep this in mind, especially when reading manuals and HOWTOs. Often the documentation refers to parameters and, in doing so, they include variables, as well as the bash special parameters, such as $1 and so on. In keeping with this, we will look at why it is advisable to quote the parameters when we use them on the command line or within scripts. Learning this now can save us a lot of pain and heartache later, especially when we start looking at loops.

First, the correct term that we should use for reading the value of variables is parameter expansion. To you and me, this is reading a variable, but to bash this would be too simple. The assignment ...

Get Mastering Linux Shell Scripting now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.