Debian Bug report logs - #135402
bash: ! inside double quotes

version graph

Package: bash; Maintainer for bash is Matthias Klose <doko@debian.org>; Source for bash is src:bash (PTS, buildd, popcon).

Reported by: Greg Wooledge <greg@wooledge.org>

Date: Sat, 23 Feb 2002 19:18:04 UTC

Severity: normal

Found in version 2.05a-5

Done: Matthias Klose <doko@cs.tu-berlin.de>

Bug is archived. No further changes may be made.

Toggle useless messages

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to debian-bugs-dist@lists.debian.org, Matthias Klose <doko@debian.org>, bash@packages.qa.debian.org:
Bug#135402; Package bash. (full text, mbox, link).


Acknowledgement sent to Greg Wooledge <greg@wooledge.org>:
New Bug report received and forwarded. Copy sent to Matthias Klose <doko@debian.org>, bash@packages.qa.debian.org. (full text, mbox, link).


Message #5 received at submit@bugs.debian.org (full text, mbox, reply):

From: Greg Wooledge <greg@wooledge.org>
To: Debian Bug Tracking System <submit@bugs.debian.org>
Subject: bash: ! inside double quotes
Date: Sat, 23 Feb 2002 14:09:45 -0500
Package: bash
Version: 2.05a-5
Severity: normal

The handling of the ! (exclamation point) inside "double quotes" is
rather strange.

$ echo "!"
bash: !: event not found
$ echo "\!"
\!

The first case is something I've grown accustomed to over the years
(though I hate it).  But the second case looks like a bug to me.  And
it's also very annoying.

Bug or not, there should be some way to put a ! character inside a
double-quoted string without resorting to this:

$ cdparanoia -w 2 "Babes in Toyland - Oh Yeah"\!".wav"

Ironically, the ! is handled rather well as long as there are no double
quotes involved:

$ echo !
!
$ echo \!
!
$ echo '!'
!
$ echo '\!'
\!

All of those cases look correct/reasonable to me.

-- System Information
Debian Release: 3.0
Architecture: i386
Kernel: Linux jekyll 2.2.20 #6 Sun Nov 4 09:01:42 EST 2001 i586
Locale: LANG=en_US.ISO8859-1, LC_CTYPE=en_US.ISO8859-1

Versions of packages bash depends on:
ii  base-files               3.0.2           Debian base system miscellaneous f
ii  libc6                    2.2.5-3         GNU C Library: Shared libraries an
ii  libncurses5              5.2.20020112a-4 Shared libraries for terminal hand




Reply sent to Matthias Klose <doko@cs.tu-berlin.de>:
You have taken responsibility. (full text, mbox, link).


Notification sent to Greg Wooledge <greg@wooledge.org>:
Bug acknowledged by developer. (full text, mbox, link).


Message #10 received at 135402-done@bugs.debian.org (full text, mbox, reply):

From: Matthias Klose <doko@cs.tu-berlin.de>
To: 135402-done@bugs.debian.org
Subject: Note a bug: history expansion inside of double quotes
Date: Sun, 7 Apr 2002 14:58:20 +0200
[Message part 1 (message/rfc822, inline)]
From: Chet Ramey <chet@nike.ins.cwru.edu>
To: mail@fwr.on.ca
Cc: bug-bash@gnu.org, bash@packages.debian.org, chet@po.cwru.edu
Subject: Re: Backslash quoting the history character within double-quotes
Date: Tue, 26 Mar 2002 09:52:12 -0500
> Bash Version: 2.05a
> Patch Level: 0
> Release Status: release
> 
> Description:
> The following:
> 
> HELP=Help
> echo "$HELP me rhonda\!"
> 
> gives me the following:
> 
> Help me rhonda\!
> 
> In other words, backslash quoting the history character within double-quotes does not "eat" the backslash although history expansion is disabled.
> 
> Without the backslash, !" does a history expansion equivalent to typing !" at the command line. 
> 
> I cannot switch to single quotes because I wish to expand $HELP.
> 
> Bug, weirdness or idiosyncracy?

csh-style history expansion is certainly weird and idiosyncratic.

As documented, the `!' may be escaped only with single quotes or a backslash.
Double quotes don't work because `!' is not one of the characters that are
treated specially within double quotes, according to the POSIX.2 spec and
traditional sh behavior.

You can either turn off history expansion with `set +o histexpand' or use
backslash outside double quotes.  Note that history expansion is not
normally enabled when the shell is not interactive, so removing the backslash
within a script should not be a problem.

I'd suggest something like

HELP=help
echo "$HELP me rhonda"\!

for an interactive shell.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet)

Chet Ramey, CWRU    chet@po.CWRU.Edu    http://cnswww.cns.cwru.edu/~chet/



Message sent on to Greg Wooledge <greg@wooledge.org>:
Bug#135402. (full text, mbox, link).


Message #13 received at 135402-submitter@bugs.debian.org (full text, mbox, reply):

From: Chet Ramey <chet@nike.ins.cwru.edu>
To: 135402-submitter@bugs.debian.org, doko@cs.tu-berlin.de
Cc: chet@po.cwru.edu, chet@po.cwru.edu
Subject: Re: bash: ! inside double quotes (forwarded message from Greg Wooledge)
Date: Mon, 8 Apr 2002 08:54:19 -0400
> From: Greg Wooledge <greg@wooledge.org>
> To: Debian Bug Tracking System <submit@bugs.debian.org>
> Subject: Bug#135402: bash: ! inside double quotes
> Date: Sat, 23 Feb 2002 14:09:45 -0500
> 
> Package: bash
> Version: 2.05a-5
> Severity: normal
> 
> The handling of the ! (exclamation point) inside "double quotes" is
> rather strange.
> 
> $ echo "!"
> bash: !: event not found
> $ echo "\!"
> \!
> 
> The first case is something I've grown accustomed to over the years
> (though I hate it).  But the second case looks like a bug to me.  And
> it's also very annoying.

It is annoying.

It's also not a bug.  `!' is not one of the characters for which backslash
retains its special meaning inside double quotes.  It's not worth breaking
posix compliance for this.

> Bug or not, there should be some way to put a ! character inside a
> double-quoted string without resorting to this:

Turn off history expansion, perhaps temporarily.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet)

Chet Ramey, CWRU    chet@po.CWRU.Edu    http://cnswww.cns.cwru.edu/~chet/



Send a report that this bug log contains spam.


Debian bug tracking system administrator <owner@bugs.debian.org>. Last modified: Wed Dec 6 07:42:53 2023; Machine Name: buxtehude

Debian Bug tracking system

Debbugs is free software and licensed under the terms of the GNU Public License version 2. The current version can be obtained from https://bugs.debian.org/debbugs-source/.

Copyright © 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson, 2005-2017 Don Armstrong, and many other contributors.