bug-bash
[Top][All Lists]
Advanced

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

Exclamation points in quoted strings


From: Ethan Glasser-Camp
Subject: Exclamation points in quoted strings
Date: Fri, 12 Oct 2007 22:45:32 -0400
User-agent: Mozilla-Thunderbird 2.0.0.4 (X11/20070828)

-----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.

ethan@sundance:~$ set -H
ethan@sundance:~$ echo "hi!"
bash: !": event not found
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$

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-----




reply via email to

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