Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to escape the bang (!) character in Linux bash shell?

Tags:

I cannot for the life of me figure out how to escape the ! character in Bash. For example, I want to print this:

Text text text!

I've tried this:

echo "Text text text\!" 

but that prints this instead:

Text text text\!

(with an extra backslash).

How can I do this?

like image 581
Nick Avatar asked Nov 30 '14 19:11

Nick


People also ask

How do I escape exclamation mark in bash?

In addition to using single quotes for exclamations, in most shells you can also use a backslash \ to escape it.

How do you exit ampersand in Linux?

When working at the command line or with batch files, you must take one of two actions when you use strings that contain an ampersand. Either you must escape the ampersand by using the caret (^) symbol, or you must enclose the string inside quotation marks.

What does [- Z $1 mean in bash?

$1 means an input argument and -z means non-defined or empty. You're testing whether an input argument to the script was defined when running the script. Follow this answer to receive notifications.


2 Answers

Try this:

 echo 'Text text text!' 

or

 echo "Text text text"'!' 

or

 echo -e "Text text text\x21" 
like image 152
Cyrus Avatar answered Sep 27 '22 20:09

Cyrus


Single quote:

echo 'Text Text Text!' 

That does it for me.

like image 28
Peregrino69 Avatar answered Sep 27 '22 21:09

Peregrino69