In all contexts in which a character "X" has special meaning to bash, it should be possible to insert that character literally by writing "\X". This fails in one case: where "X" is "!", and the context is inside double quotes. Reproducible: Always Steps to Reproduce: 1. echo "hi there!0" 2. echo "hi there\!0" 3. echo hi there\!0 4. echo "hi there$0" 5. echo "hi there\$0" 6. echo hi there\$0 Actual Results: 1. bash: !0: event not found 2. hi there\!0 3. hi there!0 4. hi there/bin/bash 5. hi there$0 6. hi there$0 Expected Results: 1. bash: !0: event not found 2. hi there!0 3. hi there!0 4. hi there/bin/bash 5. hi there$0 6. hi there$0 Note the difference in number 2. The following patch (adding "!" to the "slashify_in_quotes" set) seems to fix the problem: --- syntax.h-orig 2006-06-23 05:45:22.000000000 +1200 +++ syntax.h 2008-05-31 16:23:36.000000000 +1200 @@ -23,7 +23,7 @@ /* Defines for use by mksyntax.c */ -#define slashify_in_quotes "\\`$\"\n" +#define slashify_in_quotes "\\`$\"!\n" #define slashify_in_here_document "\\`$" #define shell_meta_chars "()<>;&|"
You might want to send this to bug-bash@gnu.org to see if this is a bug or intended behavior. Is it a regression, or has bash always done this?
Reported to bug-bash@gnu.org. Discussion is here: http://groups.google.co.nz/groups?as_ugroup=gnu.bash.bug&as_usubject=backslash-bang After a great deal of dodging and ducking, it now seems his position is "broken as designed".
OK, it appears this behaviour is documented in section 3.1.2.3 of the bash reference http://www.gnu.org/software/bash/manual/bashref.html