bug-bash
[Top][All Lists]
Advanced

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

Re: inconsistent treatment of backslash-bang"


From: Chet Ramey
Subject: Re: inconsistent treatment of backslash-bang"
Date: Fri, 18 Jul 2008 01:02:18 -0400
User-agent: Thunderbird 2.0.0.14 (Macintosh/20080421)

Lawrence D'Oliveiro wrote:
Chet Ramey wrote:

Chet Ramey wrote:

Yes, this is where the semantics of history expansion clash with traditional
shell behavior. Only single quotes inhibit history expansion.
In that case, situation number 3 is producing the wrong result, since there
are no single quotes there, only a backslash.
OK, you got me.  Unquoted backslashes inhibit history expansion also.

But how come the backslash in double-quotes is both 1) inhibiting history
expansion, and 2) causing a backslash to be printed?

If it was being treated purely as a literal backslash, I would expect the
same output as case 1 in my bug report. If it was meant to be inhibiting
history expansion, I would not expect to see it printed as well. Either do
one or the other, not both.

Do you begin to see the inconsistency here?

Here's the deal.  Only single quotes and backslashes quote the history
expansion character.  Double quotes don't matter -- csh doesn't let them
inhibit history expansion, so bash doesn't.  If a backslash appears in
double quotes, the history expansion code treats it as if it were
unquoted -- only single quotes count.  So a double-quoted \! is ignored
by history expansion and passed as is to the rest of the word expansions.

Since ! is not one of the characters for which Posix says the backslash
will act as an escape, the rest of the word expansions leave it alone.
The result is \!.

This is explained pretty well in the HISTORY EXPANSION section of the
manual page.

Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer

Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/




reply via email to

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