-bash: !": event not found [closed]

2020-02-02 02:55发布

How do I fix this bash terminal? Why would the '!' suddenly be a problem and the need for quotation marks are no longer seem to be necessary to produce the string. Did I break something? If so how do I reset it to factory setting? I'm sure it was working properly yesterday

Last login: Sat Oct 18 15:30:48 on ttys001
Michels-MacBook-Pro:~ michelfrechette$ echo "hello, world!"
-bash: !": event not found
Michels-MacBook-Pro:~ michelfrechette$ echo hello, world
hello, world
Michels-MacBook-Pro:~ michelfrechette$ echo "hello, world"
hello, world 

-bash: !": event not found, this is curious.

1条回答
在下西门庆
2楼-- · 2020-02-02 03:46

Running

set +H

will turn off the offending (history expansion) functionality in its entirety. Putting this in your ~/.bashrc is a common practice.

Alternately, you can modify the histchars variable to change the characters used to trigger history expansion (by default, !), quick substitution (by default, ^) and comments (by default, #).

As yet another option, using single- rather than double-quotes avoids triggering the shell feature in question.

查看更多
登录 后发表回答