bug-bash
[Top][All Lists]
Advanced

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

Re: bash: exclamation mark is not literal within double quotes


From: Richard Neill
Subject: Re: bash: exclamation mark is not literal within double quotes
Date: Thu, 16 Dec 2004 04:24:34 +0000
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20040913



Chet Ramey wrote:
Machine Type: i586-mandrake-linux-gnu

Bash Version: 2.05b
Patch Level: 0
Release Status: release

Description:
        Error in the documentation. The manual says:


The current version of bash is 3.0.  The bash-3.0 manual page says:

When command history is being used, the double quote may not be used to
quote the history expansion character.

Chet


Indeed it does. However, it's somewhat confusing, because the manual includes both:

(1)     "When  the command history expansion facilities are being used,
        the history expansion character, usually !, must be quoted to
        prevent  history expansion."

and

(2)     Enclosing characters in double quotes preserves the  literal    
value of all characters within the quotes, with the exception of $, `, and \. The characters $ and ` retain their special meaning within double quotes. The backslash retains its special meaning only
        when followed by one of the following characters: $, `, ", \, or
        <newline>.  A double quote  may  be quoted within double quotes
        by preceding it with a backslash.  When command history is being
        used, the double quote may not be used to quote the history
        expansion character."


The first tells me that I *must* quote it; the second tells me that I cannot do so!


May I suggest the following changes:

1)It is a bug that ! cannot be quoted within double quotes, not even by backslash. For example, the following ought to work:
        
        WARNING="Bad $USER\! Go $HOME\!"  ; echo $WARNING


2)Shouldn't history expansion be off in a shell script anyway?


3)Personally, I still find the paragraph (2) unclear. It seems to me that someone making a quick reference to quoting won't understand it. May I suggest this instead:

        Enclosing characters in double quotes preserves the  literal    
value of all characters within the quotes, with the exception of $, `, and \. The history expansion character, usually ! is
        also special.

        The characters $, ` and ! retain  their  special  meaning
        within  double  quotes. The  backslash retains its special
        meaning only when followed by one of the following characters:
        $, `, ", \, !,     or <newline>.  \$, \`, \", \! and \\ result in
        literal $,`,",!,\ respectively. \<newline> is ignored.

        " and ` will nest as expected without requiring addition
        escapes: eg echo "Today is `date "+%Y %m %d"`."
        

Please do change the behaviour to allow \! Otherwise, one has to write really contrived scripts such as:
        
        echo "Hello $USER"'!'" How are you?"


Regards

Richard







reply via email to

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