[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
Fri, 3 May 2019 19:46:06 +0800
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2
On 5/3/2019 2:52 AM, Andy Chu wrote:
On Thu, May 2, 2019 at 10:56 AM Greg Wooledge wrote:
On Fri, May 03, 2019 at 01:05:47AM +0800, KHMan wrote:
echo "[` echo \" \\" \" `]" # [ " ] (A)
So my question is, what did bash do in (A), which seems to affect the
specific case of the double quote char only?
At this point you either run away screaming, or you just admit that
everyone was *correct* when they told you that you should use $(...)
instead of `...` because backslash handling inside `...` is too surprising.
Yeah I would agree to just use $() and get on with life. It's accepted
everywhere, so you can safely modify existing shell scripts to use $()
instead of `` whenever there's an issue.
I implemented part of the surprising behavior of \" inside `` for OSH
recently, because virtualenv depended on it. I was not able to come up
with any rule that didn't involve special cases for a specific number of
backslashes. I ended up implementing something slightly simpler that ran
virtualenv, but that disagrees with existing shells in at least one case.
No I do not care to revisit it :)
I implemented most of the highlighting features for shell scripts
for the Scintilla edit control (Notepad++, Geany, SciTE, etc.) in
the last 10 years. I would like to get to the bottom of this
thing. Scintilla recognizes nested strings of all types since
2012, but I didn't want to deal with escape behaviour then. My
objective for this is to implement enough of two level nested
escape behaviour to minimize highlighting glitches.
Coders can end up with this because they might start with
`command` somewhere and when the script evolve they might do the
convenient thing and stick it in a "string". Then if they
encounter a problem with \" they will just add backslashes until
it works. The script will work and they will be happy -- unless
their editor messes up highlighting. To fix the latter, I need to
know how bash is parsing those things.
Anyway, editor users have a talent of hitting all kinds of dusty
corners and so here I am asking about bash behaviours. :-)
Kein-Hong Man (esq.)