Quoting Rules and Situations

Now that you know the basics about quoting, let's look at some additional rules that will help you use quoting effectively.

Quoting Ignores Word Boundaries

In English, you are used to quoting whole words or sentences. In shell programming, the special characters must be quoted, but it does not matter whether the regular characters are quoted in the same word, as follows:

$ echo "Hello; world"
Hello; world

You can move the quotes off word boundaries as long as any special characters remain quoted. This command produces the same output as the preceding one:

$ echo Hel"lo; w"orld

Of course, it is easier to read the line if the quotes are on word boundaries. This simple example illustrates the manner in which quoting ...

Get Sams Teach Yourself Shell Programming in 24 Hours, Second Edition 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.