Next: , Previous: , Up: Top   [Contents][Index]


3 Escaping special characters

A ‘$’ preceded by a backslash looses its special meaning. For example, supposing that the variable USER is set to ‘root’, the string:

An escaped \$USER is not expanded, unescaped $USER is.

will be expanded as follows:

An escaped \$USER is not expanded, unescaped root is.

The \ character must be escaped similarly:

Escape your \\ ⇒ Escape your \

This escaping can be turned off using the -Wno-escape option (see feature control).

When expanding quoted strings in complex variable references, the following sequences are substituted with their second character: ‘\$’, ‘\\’, ‘\"’, ‘\'’. For example (assuming VAR is not defined):

${VAR:-'quoted string'} ⇒ quoted string
${VAR:-a lone \' character} ⇒ a lone ' character

These rules apply also if the default value is enclosed in double quotes:

${VAR:-"Escape \\, \$ and \" in quoted context"}

The -Wno-escape option does not affect escapes in variable substitutions.