Using quotation marks to enclose a construct in a shell script
A $N construct in a shell script can be enclosed in
double or single quotation marks.
- When double quotation marks are used, the parameter is replaced
by the appropriate value from the command line. For example, suppose
that the file search contains:
If you enter the command:grep "$1" *
the parameter value 'two words' replaces the construct $1 in the grep command:search 'two words'
If the grep command does not contain the double quotation marks, the parameter replacement would result in:grep "two words" *
which has an entirely different meaning.grep two words *
- When you use single quotation marks to enclose a $N
construct in a shell script, the $N is not replaced
by the corresponding parameter value. For example, if the file search contains:
grep searches for the string $1. The $1 is not replaced by a value from the command line. In general, single quotation marks are “stronger” than double quotation marks.grep '$1' *