Using Double Quotes

In many cases, you will need to quote some meta-characters but allow others to be evaluated by the shell. For example, the following echo command contains some meta- characters that must be quoted and others that should not:

$ echo '$USER owes <-$1250.**>; [ as of (`date +%m/%d`) ]'

Because the string is single quoted, the output is easy to predict—what you see is what you get:

$USER owes <-$1250.**>; [ as of (`date +%m/%d`) ]

As you can imagine, this is not exactly what you wanted; the single quotes have prevented variable substitution and command substitution from occurring, thus the variable $USER, which contains the username of the current user, was not replaced with the appropriate value and the date command was not ...

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.