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?
In addition to using single quotes for exclamations, in most shells you can also use a backslash \ to escape it.
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.
$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.
Try this:
echo 'Text text text!'
or
echo "Text text text"'!'
or
echo -e "Text text text\x21"
Single quote:
echo 'Text Text Text!'
That does it for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With