[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Question about escaping in backquote string in double qu
Re: [Help-bash] Question about escaping in backquote string in double quoted strings
Wed, 15 May 2019 01:06:54 +0800
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2
On 5/15/2019 12:05 AM, Chet Ramey wrote:
On 5/2/19 1:05 PM, KHMan wrote:
I have a question about escaping of the double quote char in a backquote
command string nested inside a double quoted string. I have been trying out
an example from the Morbig paper and looking at the bash ref man but
couldn't figure things out.
Here is a slightly adjusted example from page 4, Example 2.5. Output is at
right after the comment #.
echo "[` echo \" \\" \" `]" # [ " ] (A)
OK, let's look at A. I have simplified the explanation by breaking things
into separate steps, even if the code itself performs multiple steps in a
single pass. All the quoted text snippets are from the POSIX standard.
The parser takes this and applies the double-quoting rules. The command
substitution rules enter the picture because POSIX leaves enough behavior
undefined so that the double-quoted string can be terminated by a double
quote in the backquoted command substitution (ksh93 does this, for
The bash parser doesn't allow quotes in a command substitution to terminate
a double-quoted string that was started outside it, and doesn't remove
backslashes until word expansion, so we have
[snip snip snip]
Thank you, I will spend some time to digest what you have written.
Please ignore my other posting on the source code, that was my
last resort because everyone else was telling me to just use
In recent years, this particular string nesting combination has
caused problems with syntax highlighting for Scintilla-based
editors (Geany, Notepad++, SciTE, etc.) Nested strings I sort of
fixed, but char escaping in nested strings was a real headache
that I postponed until now. While I could analyze and draw up
behavioral charts, I couldn't find anything that clearly explained
the process. So I have been doing a lot of groping in the dark.
This is not a highlighting bug ticket that any other contributor
want to touch, ha ha.
I'll probably implement a reasonable subset, then wait for the
next bash syntax highlighting bug ticket.
Kein-Hong Man (esq.)