Escaping characters
Created by: skylerberg
Like other shells we will need to allow the user to escape characters and strings. I would like to discuss the details here. Escaping is surprisingly involved in posix shells with four escaping mechanisms:
- Backslash: Escape the following character.
- Single quotes: Preserve literal value of all strings between quotes.
- Double quotes: Escape most characters between quotes with several exceptions
- Dollar sign retains meaning.
- Backtick retains meaning.
- Backslash retains its meaning only when followed by a backtick, dollar sign, backslash, or newline. Otherwise it is preserved.
- Heredoc: Redirect standard input to read a multiline string provided at the command line. This string is escaped similar to double quotes. E.g.,
<<EOF
. Zsh and bash actually implement escaping within heredocs in an incompatible way. - Herestring: Not part of posix, but provided by Bash and other shells. It is like a one line heredoc, but at least in bash it provides no escaping. E.g.,
<<<some string
.
The point of all this is to say that escaping is more complicated than meets the eye and I would like to discuss our approach to it here.