[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: escaping ! in quoted string gives wrong result
From: |
Andy Isaacson |
Subject: |
Re: escaping ! in quoted string gives wrong result |
Date: |
Fri, 18 Jun 2004 11:58:36 -0500 |
User-agent: |
Mutt/1.4.1i |
On Fri, Jun 18, 2004 at 01:08:18AM -0400, Chet Ramey wrote:
> adi@pirx.hexapodia.org wrote:
> >Bash Version: 2.05b
> >
> >Description:
> > Like some other shells, bash interprets ! inside double quotes.
> > However, bash does not handle escaped ! like other shells.
> >
> > "\!foo" should turn into `!foo' before being passed to the command.
>
> It should not. `!' is not one of the characters that is treated
> specially when in a double-quoted string. This is one of the places
> where bash's sh heritage and the csh-derived history expansion features
> collide.
I guess I don't understand your argument. "!foo" is a history expansion
in bash, and I'm willing to accept that it should be ([cz]sh do so as
well). Ergo, ! is treated specially in double-quotes. The problem
arises when attempting to include a literal ! in a double-quoted string;
you can't say `echo "!foo"' (that's a history expansion) and you can't
say `echo "\!foo"' (that results in the string "\!foo").
I'm claiming that Bash should do the same thing that zsh and csh do, and
interpret `a.out "\!foo"' in the most useful way; a.out should receive
the C-style string "!foo" in argv[1], instead of the "\!foo" which it
currently receives.
(If I've misunderstood what you meant by "treated specially", my
apologies, and please feel free to educate me (or point me at a
definition, even source code.))
-andy