Escaping Exclamation Marks in Bash
If you’ve ever committed to Git in either frustration or excitement, you’ve probably seen a message like this:
1 2 |
|
When Bash encounters an exclamation mark under certain conditions, it tries to expand the expression to the last matching command in your history. For example:
1 2 3 4 5 6 7 8 9 10 |
|
Notice that the second command !e
was expanded to the previous echo "Hello, World"
statement, and !l
is expanded to the previous ls
statement.
This is cool, but can also be annoying if that’s not what you want.
Fortunately there’s a workaround.
1 2 3 4 5 6 7 8 9 |
|
As far as I can tell, these solutions work in both Linux, and Git Bash in Windows.
You can also work around this by leaving of the -m
and editing your commit message in vim like a real developer
A couple pages I found helpful when figuring this out:
- http://superuser.com/questions/133780/in-bash-how-do-i-escape-an-exclamation-mark
- http://www.unixli.com/q/answers-why-does-the-exclamation-mark-sometimes-upset-bash-19252.html