Shell Quoting


Escaping Characters

Certain characters cause the shell to interpret commands and arguments differently. The primary example is the space character, which the shell interprets as a delimiter between tokens.

These characters can be escaped to prevent their misinterpretation. The escape character is the backwards slash (\).

a=foo\ bar

The primary challenge with escaping characters is that every time the shell interprets an escaped character, the escape is removed. Commands that will be passed between shells can require multiple escapes.


Quoting

If a string is quoted within single quotes ('), it is treated as a literal string. No expansion will apply to the value.

The single quote character can not be used within a string quoted by single quotes, even when escaped.

If a string is quoted within double quotes ("), it is treated as a single token. command expansion does apply to the value.

The double quote character can be used within a string quoted by souble quotes if it is escaped. Similarly, to use the literal characters that trigger command expansions ($, `), escape them. The escape character itself (\) also needs to be escaped to be used literally.


CategoryRicottone

Shell/Quoting (last edited 2023-01-30 02:50:13 by DominicRicottone)