Quoting in the shell
Quotes are something that we take for granted, not only in Linux but also in a lot of other applications. In this recipe, we are going to deal with how quotes work, which quotes to use, and how to make sure that your quoted part of the script behaves as you intended.
Getting ready
Using quotes is incredibly important in Linux, not only in shell scripts but also in any other application that uses text. In this context, quotes behave pretty much the same way as brackets do in mathematical expressions—they offer us the way to change how an expression is evaluated. Almost all command-line tools use a space as a delimiter that tells the tool where one string ends and another one begins. You probably ran into this when you tried to use a file or a directory that has a space in its name. Usually, we solve this problem by using an escape character (\
), but it makes it much easier to read if we apply quotes.
This is not the only reason we use quotes,...