bug-bash
[Top][All Lists]
Advanced

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

Re: escaping exclamation in double quoted string


From: Bob Proulx
Subject: Re: escaping exclamation in double quoted string
Date: Fri, 27 Jul 2007 17:37:43 -0600
User-agent: Mutt/1.5.9i

John Tromp wrote:
>       echo "hi\!" still shows the backslash

Thank you for your report.  However this is intended behavior.  And it
is also documented!  :-)

  man bash

  Enclosing characters in double quotes preserves the literal value of
  all characters within the quotes, with the exception of $, ‘, \,
  and, when history expansion is enabled, !.  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.  If
  enabled, history expansion will be performed unless an ! appearing
  in double quotes is escaped using a backslash.  The backslash
  preceding the ! is not removed.

The important part for this is:

  "The backslash preceding the ! is not removed."

This is also required by the POSIX docs.

  
http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_02_01

  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>

Hope that helps.

Bob




reply via email to

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