This article introduces how to escape ! (exclamation mark) in Bash command line in Linux PC/server environments. I wanted to create a bash function that returns markdown when given an image, but I ran into the exclamation mark barrier.
! itself isn’t used much normally, but it’s a quite convenient command. It’s well known that you can view history with ctrl+r, but for example, if you execute pwd and then execute !p or !pw, pwd will be executed. It’s like that. However, escaping this was quite tricky.
bash - How to escape ! exclamation mark in Bash (140827)|teratail
Question
How do you escape ! exclamation mark in Bash?
$ echo "\)"
\
I’m escaping with , but even \ is being output…
Answer
echo '!'"[$(echo "hgoe")]($(echo "hgoe"))"
Impressions
So in bash, you can concatenate strings with ” and "". I didn’t know that. Normally you can’t do that, right? It’s tricky, or should I say.
Normally you’d think to do something like echo "" + ” ;, but this is unique to command line.