Sometimes I feel the urge to put some more expressiveness in my git commit messages. Unfortunately bash does not seem to like this.
iblue@silence ~/git/wargames $ git commit -m "Frustrating <insert object of frustration here>!"
-bash: !": event not found
Escaping with a backslash helps, but this includes the backslash in the commit message.
How do I escape the exclamation mark in bash correctly?
'echo -e' and 'printf' interpret escaped octal, hex, and Unicode codes. In cases where you're using either of those, you can use "\041" (the octal for the "!") or "\x21" (the hex) to stand-in for the exclamation point.
Bash maintains the history of the commands executed in the current session. We can use the exclamation mark (!) to execute specific commands from the history.
Note the % <percent-sign> character within the printf argument. We can ignore its special meaning by escaping it with another <percent-sign>: %%. This preserves the literal value.
The escape (\) preceding a character tells the shell to interpret that character literally. With certain commands and utilities, such as echo and sed, escaping a character may have the opposite effect - it can toggle on a special meaning for that character.
Exclamation mark is preserved literally when you include it in a single-quoted string.
Example:
git commit -m 'Frustrating <insert object of frustration here>!'
Have a try this one
git commit -m "Frustrating <insert object of frustration here>"'!'
If in the middle of string then
"hello"'!'"world"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With