Contents
How do I escape an exclamation mark in Bash?
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. Thanks for contributing an answer to Stack Overflow!
What does the exclamation mark in the command prompt mean?
! invokes history expansion, a feature that originally appeared in the C shell, back in the days before you could count on terminals to have arrow keys. It’s especially useful if you add the current command number to the prompt ( PS1=”\\!$ “) so you can quickly look at your screen to get numbers for past commands.
When to use a backslash before an exclamation mark?
Note that in double quotes, a backslash before the exclam prevents history expansion, BUT the backslash is not removed in such a case. So it’s better to use single quotes, so you’re not passing a literal backslash to curl as part of the URL.
Is there way to disable history expansion in zsh?
You can disable it in Zsh with set -K. If there isn’t a longer answer here there’s certainly one on Super User, since I’ve read one recently. In the bash man page you can find a huge section titled HISTORY EXPANSION on the matter. You can do a whole host more than just run the last command, or command number X.
Can you type an exclamation point on a keyboard?
I can’t type an exclamation mark with my keyboard. I can type other symbols that require the shift key (~ @ # $, etc) but Shift + 1 does not give an exclamation point.
Can you use an exclamation mark with Curl?
As well as the answer given by Daniel, you can also simply turn off history expansion altogether if you don’t use it with set +H. I would personally do single quotes, but for completeness, I will also note since it is a URL, you can encode the ! as %21, e.g. curl -v http://example.org/%21132 .