Section 5.16. Quoting


[Page 187]

5.16. Quoting

There are often times when you want to inhibit the shell's wildcard-replacement, variable-substitution, and/or command-substitution mechanisms. The shell's quoting system allows you to do just that. Here's the way it works:

  • Single quotes ( ' ) inhibit wildcard replacement, variable substitution, and command substitution.

  • Double quotes ( " ) inhibit wildcard replacement only.

  • When quotes are nested, only the outer quotes have any effect.

The following example illustrates the difference between the two different kinds of quotes:

$ echo 3 * 4 = 12         ...remember, * is a wildcard. 3 a.c b.c c.c 4 = 12 $ echo "3 * 4 = 12"       ...double quotes inhibit wildcards. 3 * 4 = 12 $ echo '3 * 4 = 12'       ...single quotes inhibit wildcards. 3 * 4 = 12 $ name=Graham 


By using single quotes (apostrophes) around the text, we inhibit all wildcarding, variable, and command substitutions:

$ echo 'my name is $name - date is `date` ' my name is $name and the date is `date` 


By using double quotes around the text, we inhibit wildcarding, but allow variable and command substitutions:

$ echo "my name is $name - date is `date`" my name is Graham - date is Wed Feb  2 23:14:56 CST 2005 $ _ 





Linux for Programmers and Users
Linux for Programmers and Users
ISBN: 0131857487
EAN: 2147483647
Year: 2007
Pages: 339

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net