I want to do something like bzr commit -m "It works!". I can sort of escape the exclamation mark by doing bzr commit -m "It works\!". However, then my commit message includes the backslash. How do I escape the exclamation mark, while still ignoring the backslash?
|
|
||||
|
Since you do not depend on bash to expand variables in your commit message you could use single quotes instead. Strings in single quotes are not expanded by bash.
|
|||||||||
|
|
Old question I know, but for future searchers: You can also use this method if you want double quotes as well as the exclamation:
Note to user N13, before you edit my answer again: This works even if the Eg, this works:
|
||||
|
|
Turn off history expansion
or
|
|||||
|
|
Use single quotes (') instead of double quotes ("). Single quotes turn off all interpretation of the stuff in them, while double quotes only turn off some.
|
||||
|
|
|
I just now found another way, that will at least work with echo'ing strings (sentences) you want to punctuate with an exclamation point. It does an end-run, more or less, around BASH histexpand and takes only a bit longer to code. The hex for an exclamation point, as listed here http://www.ascii-code.com/ , is 21, so if you put \x21 at the end of your string, "echo -e $foo", make $foo its own expanded echo [ie, foo=$(echo -e "$foo") ], what you get when you echo $foo again is the string with an ! at the end. And no switching histexpand either. Works for sure in BASH 4+. Earlier versions, ymmv. BZT |
|||
|
|

bzr commit -m "It works"!works, too. – kba May 18 at 13:59