How do I escape an exclamation mark in bash?
Have a try this one
git commit -m "Frustrating <insert object of frustration here>"'!'
If in the middle of string then
"hello"'!'"world"
In addition to using single quotes for exclamations, in most shells you can also use a backslash \
to escape it. That is:
git commit -m "Frustrating <insert object of frustration here>\!"
However, I personally recommend disabling bash expansion in you shell by adding set +H
or set +o histexpand
to your .bashrc
file.
If, like me, you never use bash expansion in your shell, disabling it will allow you to use exclamation points in any double-quote string - not only during your commits but for all bash commands.
Use single quotes instead to prevent expansion.
Exclamation mark is preserved literally when you include it in a single-quoted string.
Example:
git commit -m 'Frustrating <insert object of frustration here>!'