bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug 103756] kate: syntax highlighting error: bash and escaped quote


From: Matthew Woehlke
Subject: Re: [Bug 103756] kate: syntax highlighting error: bash and escaped quotes
Date: Mon, 02 Apr 2007 18:35:31 -0500
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.10) Gecko/20070221 Thunderbird/1.5.0.10 Mnenhy/0.7.4.0

Eric Blake-1 wrote:
Current bash.xml accepts (a), but not (b). The single qoute is
the start of string highlight. It's also not just the backtick
block, but the backtick block inside of a double quote string
block - and vice versa.

First, be aware that `` in bash 3.1 was buggy, so you should
upgrade to bash 3.2 rather than trying to figure out how the
broken 3.1 parsing worked.

x="`echo \"'\\\"\"`"    is valid
My bash highlighter thinks this is invalid. So does my brain. However bash seems OK with it. Why, I wonder? Maybe I am not clear on the expansion rules in this instance.


This is valid.  According to POSIX, the double quoted string is terminated
by the matching unquoted double quote, and within that string, the ``
string is executed on the contents of the `` with the \ quotes before any
$, `, ", \, and newline removed.  So the result is that you are executing
the command:

`echo "'\""`

Then, according to `` rules, $, `, and \ are special (but not "), so
the subshell sees the command:

echo "'\""

which is valid, and results in '" being assigned to x.

x=`echo \"'\\\"\"`      isn't
Ditto, except bash also (correctly IMO) doesn't like it.

Here, there is no surrounding "" to strip leading \ quotes
special to "".  So you are executing the command

`echo \"'\\\"\"`

and according to the rules of ``, the subshell sees:

echo \"'\\"\"

which indeed is a syntax error.

The other way around:

x=`echo "'\""`          is valid

Valid.  The subshell sees:

echo "'\""

and x is assigned '"

x="`echo "'\""`"        isn't

but both are highlighted as valid.

Invalid.  The "" ends at the first unquoted ", but that meant
that you had an unpaired `, so bash is allowed to reject this.
The difference was that by adding "" around ``, you have
to also add \ escapes around characters special to "".

That's odd, because all of the following are valid:

echo "'\""

Valid.

echo `echo "'\""`

Valid.  The inner echo results in the three characters '"<newline>,
then the `` strips the newline, and since this was the expansion
of ``, no further quoting is needed and the outer echo results
in '" again.

x="$(echo "'\"")" <-- this should be syntactically equivalent?!

$() has different rules than ``.  Inside $(), any valid script
is allowed, and by itself,
echo "'\""
is a valid script.  And inside "$()", the rules are explicit that the
contents of the $() are not subject to normal "" escapes, but
that the closing ) is found by a recursive parse.

...so this feels like a bug in bash.

No, bash is correct.  `` and $() are different, and the
rules for "``" are different from "$()".  And if it weren't
for the fact that Solaris /bin/sh still doesn't understand
$() which hampers its portable use, I would gladly ditch
`` for the nicer semantics of $().

Yike, that's bizzarre... so essentially what you are saying is that the semantics of a `` expression differ based on whether or not it occurs within quotes? That definately strikes me as unintuitive... and it's not going to make handling the issue pretty, no, not at all. :-(

I still think the doc could be clearer on this issue.

--
Matthew
Vs lbh pna ernq guvf jvgubhg fbsgjner, lbh ner n FREVBHF areq! -- Nqncgrq sebz Znggurj Jva (ivz-qri znvyvat yvfg)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]