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:
    grep "$1" *
    If you enter the command:
    search 'two words'
    the parameter value 'two words' replaces the construct $1 in the grep command:
    grep "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.
  • 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 '$1' *
    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.