Exclamation points in quoted strings

2007-10-12 Thread Ethan Glasser-Camp
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

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.

[EMAIL PROTECTED]:~$ set -H
[EMAIL PROTECTED]:~$ echo "hi!"
bash: !": event not found
[EMAIL PROTECTED]:~$ echo "hi\!"
hi\!

This is somewhat unusual; generally, characters protected by
backslashes are put through *unescaped*. Compare:

[EMAIL PROTECTED]:~$ echo "\`"
`
[EMAIL PROTECTED]:~$ echo "\""
"
[EMAIL PROTECTED]:~$ echo "hi\$"
hi$

The manual page does say explicitly, under "Quoting":

The backslash preceding the ! is not removed.

But no explanation is given for why this behavior exists. Is it part
of POSIX compliance? An implementation detail?

Ethan
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHEDFMhRlgoLPrRPwRAmj1AJ9Ch7mz87lP/NRm+8+ZqXUOULk1sACgh2Kw
1ArDcXwqPrDZOdWoz038t1E=
=7fHW
-END PGP SIGNATURE-




Re: Exclamation points in quoted strings

2007-10-14 Thread Ethan Glasser-Camp
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Chet Ramey wrote:
> 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:
> 
>   $   `   "   \   

I think I see. So the backslash isn't counting as an escape character
here, and so passes through without being removed, but does inhibit
history expansion anyhow?

Thanks a lot! I still think the behavior is confusing, but at least I
know why it happens.

Ethan
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHEtfChRlgoLPrRPwRAkonAKCsGDABs+TXOya432vkIc5z4ApEXgCg2fH9
vwlDCQgES6KEJ7jxdLHetYM=
=3FLD
-END PGP SIGNATURE-