[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Exclamation points in quoted strings
From: |
Chet Ramey |
Subject: |
Re: Exclamation points in quoted strings |
Date: |
Sun, 14 Oct 2007 22:27:14 -0400 |
User-agent: |
Thunderbird 2.0.0.6 (Macintosh/20070728) |
Ethan Glasser-Camp wrote:
> Hi,
>
> I'm not a shell script pro and I don't know much about POSIX, but I
> have found this puzzling behavior in bash, and although it is
> documented I don't really understand why bash behaves this way. I was
> hoping someone could tell me.
>
> ethan@sundance:~$ set -H
> ethan@sundance:~$ echo "hi!"
> bash: !": event not found
Only single quotes or an unquoted backslash can inhibit history
expansion. This is inherited from the features's csh heritage.
> ethan@sundance:~$ echo "hi\!"
> hi\!
>
> This is somewhat unusual; generally, characters protected by
> backslashes are put through *unescaped*. Compare:
>
> ethan@sundance:~$ echo "\`"
> `
> ethan@sundance:~$ echo "\""
> "
> ethan@sundance:~$ echo "hi\$"
> hi$
Not true, in general. Posix specifies the characters the backslash
can escape in double-quoted strings. You happened to choose three of
the five.
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>
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
Live Strong. No day but today.
Chet Ramey, ITS, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/