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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.