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 17:01:50 -0400
User-agent: Thunderbird 2.0.0.14 (Macintosh/20080421)

Lawrence D'Oliveiro wrote:
Chet Ramey wrote:

Here's the deal.  Only single quotes and backslashes quote the history
expansion character.  Double quotes don't matter ...

Then why do they cause a difference in behaviour?

Are you being deliberately obtuse?  The rest of the message explained
that the difference in behavior is due to the different csh and sh
semantics.

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.

Then why does “\!” act as “!” under any circumstances at all?

What?  Are we not talking about a single case:  the behavior of \!
when in double quotes?

I already explained that bash follows csh as closely as possible
in its history expansion implementation.  csh doesn't consider double
quotes when performing history expansion, and will allow the backslash
to quote the history expansion character.  This means that the history
expansion process will not alter the passed string and the \! will
be present in the string passed to the rest of the shell's word
expansions.

One of those word expansions is the processing of double-quoted strings.

The behavior of backslash in double-quoted strings is well-defined.  In
Posix terms:

        Enclosing characters in double-quotes ( "" ) shall preserve
        the literal value of all characters within the double-quotes,
        with the exception of the characters dollar sign, backquote,
        and backslash, as follows:
                [...]

        The backslash shall retain its special meaning as an escape
        character (see Escape Character (Backslash)) only when followed
        by one of the following characters when considered special:

                        $   `   "   \   <newline>

This means that backslash doesn't escape the !, and isn't removed.  The
\! remains in the string after word expansion.

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

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




reply via email to

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