If I run
grep "!" test.txt
it will show error
bash: !: event not found
Well, I know I actually should use grep '!'
. But how to understand the above error?
I know !
is bash special character. According to http://mywiki.wooledge.org/Quotes.
Double quotes: "..." prevents some substitutions but allows others. Every substitution that begins with a dollar sign $ is performed, as is the legacy
...
(backtick) command substitution. Backslash escaping is also performed. No word splitting or filename expansion is performed.
It doesn't mention that double quotes will affect !. Could somebody explain how does bash or grep interpret grep "!"
? What is the "event"?
grep \! test.txt
would work as well. I guess it's a bug that's why this changed behavior. – Mar 20 '17 at 16:00grep '!'
works, Whybash -c 'grep \'!\' test.txt'
doesn't work? – user15964 Mar 20 '17 at 16:05bash -c 'grep '\''!'\'' test.txt'
– Mar 20 '17 at 16:21set +o histexpand
in your.bashrc
or equivalent. – arielCo Nov 03 '18 at 21:27