9

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.

Gilles 'SO- stop being evil'
  • 98,216
  • 36
  • 202
  • 244
Michel Frechette
  • 147
  • 1
  • 2
  • 7
  • This is also BashPitfalls #23: http://mywiki.wooledge.org/BashPitfalls#echo_.22Hello_World.21.22 – Charles Duffy Oct 18 '14 at 19:55
  • 2
    possible duplicate of [how to address error "bash: !d': event not found" in Bash command substitution](http://stackoverflow.com/questions/25003162/how-to-address-error-bash-d-event-not-found-in-bash-command-substitution) – tripleee Oct 18 '14 at 20:16

1 Answers1

35

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.

Charles Duffy
  • 257,635
  • 38
  • 339
  • 400