Strong and Weak Quoting in Shell Scripts

I do now know when the terms “strong quoting” and “weak quoting” entered Unix (or Linux) shell lexicon. Despite having been the maintainer of various shells for a number of years while working for an operating system vendor, I have only come across this particular terminology over the last few years.

Strong and weak quoting is not mentioned any of the shell man pages that I checked. Typically quoting is described in a manner similar to that of the ksh88 manpage:

“Second, a single quote (‘) quotes everything up to the next single quote (this can span lines). Third, adouble quote (“) quotes all characters, except $, ‘ and , up to the next unquoted double quote. The characters $ and ‘ inside double quotes have their usual meaning (that is, parameter, command, or arithmetic substitution) except that no field splitting is carried out on the results of double-quoted substitutions. If a inside a double-quoted string is followed by , $, ‘, or “, it is replaced by the second character. If it is followed by a newline, both the and the newline are stripped. Otherwise, both the and the character following are unchanged.”

Neither is strong or weak quoting mentioned in POSIX.1-2008. Section 2.2 of that standard states that:

“Enclosing characters in single-quotes ( ” ) shall preserve the literal value of each character within the single-quotes. A single-quote cannot occur within single-quotes. Enclosing characters in double-quotes ( “” ) shall preserve the literal value of all characters within the double-quotes, with the exception of the characters backquote, , and , as follows: …”

The earliest reference I can find to this terminology in Chapter 1, Section 1.9 of Learning the Korn Shell, 1st ed. It is also used in Learning the Bash Shell. Since Bill Rosenblatt is an author of both of these books, I have to suspect that this terminology orginated with him.

Comments are closed.