[Top][All Lists]

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

Re: inconsistent treatment of backslash-bang

From: Lawrence D'Oliveiro
Subject: Re: inconsistent treatment of backslash-bang
Date: Tue, 22 Jul 2008 23:38:01 +1200
User-agent: Microsoft-Outlook-Express-Macintosh-Edition/5.0.6

Chet Ramey wrote:

> Bash and csh both permit backslash to inhibit history expansion when in
> double quotes.

If a printable character has special meaning in syntax for representing data
strings, then in any situation where it's special, it is expected to be
possible to disable that specialness by prefixing the special character with
some escape character, commonly a backslash. The combination
escape-followed-by-special literally represents the special character.

This rule is essentially universal in the *nix world. There is a good reason
for it: it's predictable, easy to follow, minimizes surprises, and doesn't
add restrictions on the data that can be represented. Exceptions should not
be made without careful thought. Certainly not inadvertently and carelessly
as a result of a bug.

And even with the specialness of bang turned off, it still doesn't work

address@hidden:~> set +H
address@hidden:~> echo "hi there!"
hi there!
address@hidden:~> echo "hi there\!"
hi there\!
address@hidden:~> echo hi there!
hi there!
address@hidden:~> echo hi there\!
hi there!

So tell me, how do you rationalize that in terms of history expansion, in a
situation where history expansion has nothing to do with it?

> Later on, in the subsequent word expansion steps, bash and csh differ.  csh
> allows backslash to act as an escape character when it precedes `!' in a
> double-quoted string, and removes it.  Bash allows backslash to act as an
> escape character only when it precedes the characters so specified in the
> Posix standard, and `!' is not one of those, so bash leaves the \! intact.

In that case, you need to fix the documentation, because that's not what
bashref section 9.3 says. Let me draw your attention again to the relevant
sentence: ³Only Œ\¹ and Œ'¹ may be used to escape the history expansion

No mention in there of any difference in behaviour due to the presence of
double-quotes. Therefore if your current explanation is to be accepted, then
that description needs some expansion.

Either fix the code to reflect the documentation, or fix the documentation
to reflect the code. What's it going to be?

reply via email to

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