why grep â!â shows âbash: !: event not foundâ?
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
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"?
bash grep special-characters
add a comment |Â
up vote
1
down vote
favorite
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"?
bash grep special-characters
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
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"?
bash grep special-characters
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"?
bash grep special-characters
bash grep special-characters
asked Mar 20 '17 at 15:44
user15964
2981516
2981516
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
4
down vote
It's not grep
that's causing it. It's your bash
that is interpreting the !
. Switch to a newer version of bash
or use single quotes '!'
to shut up bash
.
why new version has no error? Bug or some new feature?
â user15964
Mar 20 '17 at 15:55
Actually in your scenario,grep ! test.txt
would work as well. I guess it's a bug that's why this changed behavior.
â user218374
Mar 20 '17 at 16:00
Ok,grep '!'
works, Whybash -c 'grep '!' test.txt'
doesn't work?
â user15964
Mar 20 '17 at 16:05
Actually you need to realize how quoting works, single quoting , that is, in your above case. You can't slip in a single quote inside of single quotes just by escaping it. Why? Coz, the backslash ain't special inside of single quotes, the way it is special inside double quotes or in empty space. You shoud do this:bash -c 'grep '''!''' test.txt'
â user218374
Mar 20 '17 at 16:21
The History Expansion feature is still available and enabled by default as of Bash 4.4.19, and I don't expect it to be removed soon. Quote it or putset +o histexpand
in your.bashrc
or equivalent.
â arielCo
11 mins ago
add a comment |Â
up vote
0
down vote
You're looking at Bash's History Expansion feature. Some find it handy to recall previous commands, but I just put set +o histexpand
in my .bashrc
and press Ctrl+R to search for part of the command.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
It's not grep
that's causing it. It's your bash
that is interpreting the !
. Switch to a newer version of bash
or use single quotes '!'
to shut up bash
.
why new version has no error? Bug or some new feature?
â user15964
Mar 20 '17 at 15:55
Actually in your scenario,grep ! test.txt
would work as well. I guess it's a bug that's why this changed behavior.
â user218374
Mar 20 '17 at 16:00
Ok,grep '!'
works, Whybash -c 'grep '!' test.txt'
doesn't work?
â user15964
Mar 20 '17 at 16:05
Actually you need to realize how quoting works, single quoting , that is, in your above case. You can't slip in a single quote inside of single quotes just by escaping it. Why? Coz, the backslash ain't special inside of single quotes, the way it is special inside double quotes or in empty space. You shoud do this:bash -c 'grep '''!''' test.txt'
â user218374
Mar 20 '17 at 16:21
The History Expansion feature is still available and enabled by default as of Bash 4.4.19, and I don't expect it to be removed soon. Quote it or putset +o histexpand
in your.bashrc
or equivalent.
â arielCo
11 mins ago
add a comment |Â
up vote
4
down vote
It's not grep
that's causing it. It's your bash
that is interpreting the !
. Switch to a newer version of bash
or use single quotes '!'
to shut up bash
.
why new version has no error? Bug or some new feature?
â user15964
Mar 20 '17 at 15:55
Actually in your scenario,grep ! test.txt
would work as well. I guess it's a bug that's why this changed behavior.
â user218374
Mar 20 '17 at 16:00
Ok,grep '!'
works, Whybash -c 'grep '!' test.txt'
doesn't work?
â user15964
Mar 20 '17 at 16:05
Actually you need to realize how quoting works, single quoting , that is, in your above case. You can't slip in a single quote inside of single quotes just by escaping it. Why? Coz, the backslash ain't special inside of single quotes, the way it is special inside double quotes or in empty space. You shoud do this:bash -c 'grep '''!''' test.txt'
â user218374
Mar 20 '17 at 16:21
The History Expansion feature is still available and enabled by default as of Bash 4.4.19, and I don't expect it to be removed soon. Quote it or putset +o histexpand
in your.bashrc
or equivalent.
â arielCo
11 mins ago
add a comment |Â
up vote
4
down vote
up vote
4
down vote
It's not grep
that's causing it. It's your bash
that is interpreting the !
. Switch to a newer version of bash
or use single quotes '!'
to shut up bash
.
It's not grep
that's causing it. It's your bash
that is interpreting the !
. Switch to a newer version of bash
or use single quotes '!'
to shut up bash
.
answered Mar 20 '17 at 15:49
user218374
why new version has no error? Bug or some new feature?
â user15964
Mar 20 '17 at 15:55
Actually in your scenario,grep ! test.txt
would work as well. I guess it's a bug that's why this changed behavior.
â user218374
Mar 20 '17 at 16:00
Ok,grep '!'
works, Whybash -c 'grep '!' test.txt'
doesn't work?
â user15964
Mar 20 '17 at 16:05
Actually you need to realize how quoting works, single quoting , that is, in your above case. You can't slip in a single quote inside of single quotes just by escaping it. Why? Coz, the backslash ain't special inside of single quotes, the way it is special inside double quotes or in empty space. You shoud do this:bash -c 'grep '''!''' test.txt'
â user218374
Mar 20 '17 at 16:21
The History Expansion feature is still available and enabled by default as of Bash 4.4.19, and I don't expect it to be removed soon. Quote it or putset +o histexpand
in your.bashrc
or equivalent.
â arielCo
11 mins ago
add a comment |Â
why new version has no error? Bug or some new feature?
â user15964
Mar 20 '17 at 15:55
Actually in your scenario,grep ! test.txt
would work as well. I guess it's a bug that's why this changed behavior.
â user218374
Mar 20 '17 at 16:00
Ok,grep '!'
works, Whybash -c 'grep '!' test.txt'
doesn't work?
â user15964
Mar 20 '17 at 16:05
Actually you need to realize how quoting works, single quoting , that is, in your above case. You can't slip in a single quote inside of single quotes just by escaping it. Why? Coz, the backslash ain't special inside of single quotes, the way it is special inside double quotes or in empty space. You shoud do this:bash -c 'grep '''!''' test.txt'
â user218374
Mar 20 '17 at 16:21
The History Expansion feature is still available and enabled by default as of Bash 4.4.19, and I don't expect it to be removed soon. Quote it or putset +o histexpand
in your.bashrc
or equivalent.
â arielCo
11 mins ago
why new version has no error? Bug or some new feature?
â user15964
Mar 20 '17 at 15:55
why new version has no error? Bug or some new feature?
â user15964
Mar 20 '17 at 15:55
Actually in your scenario,
grep ! test.txt
would work as well. I guess it's a bug that's why this changed behavior.â user218374
Mar 20 '17 at 16:00
Actually in your scenario,
grep ! test.txt
would work as well. I guess it's a bug that's why this changed behavior.â user218374
Mar 20 '17 at 16:00
Ok,
grep '!'
works, Why bash -c 'grep '!' test.txt'
doesn't work?â user15964
Mar 20 '17 at 16:05
Ok,
grep '!'
works, Why bash -c 'grep '!' test.txt'
doesn't work?â user15964
Mar 20 '17 at 16:05
Actually you need to realize how quoting works, single quoting , that is, in your above case. You can't slip in a single quote inside of single quotes just by escaping it. Why? Coz, the backslash ain't special inside of single quotes, the way it is special inside double quotes or in empty space. You shoud do this:
bash -c 'grep '''!''' test.txt'
â user218374
Mar 20 '17 at 16:21
Actually you need to realize how quoting works, single quoting , that is, in your above case. You can't slip in a single quote inside of single quotes just by escaping it. Why? Coz, the backslash ain't special inside of single quotes, the way it is special inside double quotes or in empty space. You shoud do this:
bash -c 'grep '''!''' test.txt'
â user218374
Mar 20 '17 at 16:21
The History Expansion feature is still available and enabled by default as of Bash 4.4.19, and I don't expect it to be removed soon. Quote it or put
set +o histexpand
in your .bashrc
or equivalent.â arielCo
11 mins ago
The History Expansion feature is still available and enabled by default as of Bash 4.4.19, and I don't expect it to be removed soon. Quote it or put
set +o histexpand
in your .bashrc
or equivalent.â arielCo
11 mins ago
add a comment |Â
up vote
0
down vote
You're looking at Bash's History Expansion feature. Some find it handy to recall previous commands, but I just put set +o histexpand
in my .bashrc
and press Ctrl+R to search for part of the command.
add a comment |Â
up vote
0
down vote
You're looking at Bash's History Expansion feature. Some find it handy to recall previous commands, but I just put set +o histexpand
in my .bashrc
and press Ctrl+R to search for part of the command.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
You're looking at Bash's History Expansion feature. Some find it handy to recall previous commands, but I just put set +o histexpand
in my .bashrc
and press Ctrl+R to search for part of the command.
You're looking at Bash's History Expansion feature. Some find it handy to recall previous commands, but I just put set +o histexpand
in my .bashrc
and press Ctrl+R to search for part of the command.
answered 13 mins ago
arielCo
738510
738510
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f352631%2fwhy-grep-shows-bash-event-not-found%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password