Enter a string containing "!!" on a shell without it being interpretted

2

I'm trying to send a string that contains "!!" in it. However, every time I execute it on zsh, zsh replaces !! with the last command entered. How can I get zsh to not interpret "!!"? I have also confirmed the same thing happens when I just use sh.

David

Posted 2013-10-23T20:40:25.960

Reputation: 147

2use single quotes '!!' – suspectus – 2013-10-23T20:42:52.757

Answers

1

Have you tried quoting your string with single quotes instead of double quotes?

https://www.linuxquestions.org/questions/programming-9/bash-double-quotes-don%27t-protect-exclamation-marks-545662/

bbbco (04:45 PM) ~/ $ echo "Exclamation!!"
echo "Exclamationecho "Exclamationecho 'Exclamation!!'""
Exclamationecho Exclamationecho Exclamation!!

bbbco (04:43 PM) ~/ $ echo 'Exclamation!!'
Exclamation!!

bbbco

Posted 2013-10-23T20:40:25.960

Reputation: 126

2

Have you tried one backslash for every character?

\!\!

Preceding characters with backslash (one backslash per one character) should give in effect exactly this character, not replaced (it is not interpreted then).

pbies

Posted 2013-10-23T20:40:25.960

Reputation: 1 633

2to aid googling for the OP, it's called 'escaping'. – Sirex – 2013-10-23T20:48:10.287

0

As mentioned by others, quoting or escaping helps to prevent the history expansion in the current command line.

But, you can also use

unsetopt BANG_HIST

to disable the special treatment the character ! completely. (Put this is your ~/.zshrc to make it permanent.)

mpy

Posted 2013-10-23T20:40:25.960

Reputation: 20 866