[Top][All Lists]

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

Re: Backslash quoting the history character within double-quotes

From: Chet Ramey
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

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    address@hidden    http://cnswww.cns.cwru.edu/~chet/

reply via email to

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