echo "#!" fails -- "event not found"

amazon echo
echo dot
echo sound
echo book
echo greek mythology
echo show
echo medical
echo song

The following fails and I don't understand why:

$ echo "#!"

the following also fails with the same error message:

$ echo "\#!"

the error message:

-bash: !": event not found

Why does it fail? How should the echo be done instead?

The ! character is used for csh-style history expansion.

If you do not use this feature, set +o histexpand (aka set +H) turns off this behavior. It is turned off for scripts, but often enabled for interactive use. In such cases, my personal recommendation is to turn it off permanently by adding set +o histexpand to your .bash_profile (or .bashrc if you don't have a .bash_profile; this is more complex than I want to try to fit into a parenthetical).

As a workaround, if for some reason you cannot or don't want to turn off and forget about this legacy csh feature, you can use single quotes instead of double quotes -- keeping in mind, of course, their different semantics. If you need to combine quoting with variable interpolation, for example, you can change

echo "#!$SHELL"  # oops, history expansion breaks this

into

 echo '#!'"$SHELL"

(notice the adjacent single-quoted and double-quoted strings; after the shell is done with this, the quotes will be removed and the string #! will be output next to the value of the variable SHELL with no space between them) or a number of other common workarounds like

 printf '#!%s\n' "$SHELL"

Echo (3rd Gen) - Smart speaker with Alexa - Twilight , Pair with a second Echo (3rd Gen) or Echo Plus (2nd Gen) for stereo sound and add more base with an Echo Sub. Voice control your music - Ask Alexa for a song​,  Echo definition is - the repetition of a sound caused by reflection of sound waves. How to use echo in a sentence.

By default, bash supports csh compatible history-expansion.

In bash

echo #!

will only print a newline, as # starts a comment.

In

echo "#!"

the # is part of the string started with ". Such strings are still inspected by bash for special characters. ! is a special character iff it is followed by any other text.

-bash: !": event not found

In this case, bash expects the !" token to refer to a previous command in shell history starting with ", and does not find one. All by itself, ! will not trigger this behaviour:

$ echo \# !
# !

$ echo fee ! fie
fee ! fie

Finally,

$ echo !echo

produces two lines, the first line is printed by the shell to show how the pattern above expands to:

echo echo '# !'

while the second line is just the result of executing the expanded command: echo # !


See Also: The Bash man page on History Expansion

Amazon Echo & Alexa Devices / Amazon Devices, Online shopping from a great selection at Amazon Devices & Accessories Store. Online shopping for Amazon Echo & Alexa Devices from a great selection at Amazon Devices & Accessories Store.

echo '#!'

Basically, with double quotes (") aka "weak quoting", Bash does some wacky things with the string, like variable substitution. With single (') aka "strong quoting" the string is taken literally.

See e.g. here for a more in-depth explanation of quoting.

Echo, In audio signal processing and acoustics, echo is a reflection of sound that arrives at the listener with a delay after the direct sound. The delay is directly  Define echo. echo synonyms, echo pronunciation, echo translation, English dictionary definition of echo. n. Greek Mythology A nymph whose unrequited love for

Another workaround may be to put an extra space after the "!" :

# echo "#! "
#!

Echo (mythology), connects to the Alexa Voice Service to play music, ask questions, make calls, send and receive messages, provide information, news, sports scores, weather, and more—instantly. Amazon Echo is a hands-free speaker you control with your voice. Echo connects to the Alexa Voice Service to play music, ask questions, make calls, send and receive messages, provide information, news, sports scores, weather, and more—instantly.

In my case all commands are working. Maybe you can specify your environment.

$ echo "\#\!"
\#\!
$ echo "#!"
echo "#"
#
$ echo "#!"
echo "#"
#
$ echo $BASH_VERSION
3.2.48(1)-release

Echo (2nd Generation) - Smart speaker with Alexa , is made by sound waves bouncing off a hard surface. Echo Global Logistics, Inc. (NASDAQ: ECHO) is a leading provider of technology-enabled transportation and supply chain management services. Headquartered in Chicago with more than 30 offices around the country, Echo offers freight brokerage and Managed Transportation solutions for all major modes, including truckload, partial truckload, LTL, intermodal, and expedited.

What is an Echo?, or what ever you want to call it.. since you even have that option .. An echocardiogram (echo) is a test that uses high frequency sound waves (ultrasound) to make pictures of your heart. The test is also called echocardiography or diagnostic cardiac ultrasound. Quick facts

Amazon Echo vs. Dot, Echo definition is - the repetition of a sound caused by reflection of sound waves. How to use echo in a sentence. Liverpool Echo, the very latest Liverpool and Merseyside news, sport, what's on, weather and travel. Plus the latest Liverpool FC and Everton FC news.

Is there added monthly costs?, Echo definition, a repetition of sound produced by the reflection of sound waves from a wall, mountain, or other obstructing surface. See more. Echo is an absolute godsend. Echo is an absolute godsend! After years of trying to get to the pharmacy on time either after work or of a Saturday morning or begging someone to collect on my behalf - it is now wonderful to get them posted through my letterbox! It means I now get my prescriptions on time and am able to manage my asthma so much

Comments
  • rici's answer to a duplicate is really stellar if you want a detailed, long exposition.
  • Rolled back the edit with @GaborJozan's answer as that was posted separately anyway, but has the obvious flaw that it adds a space where none was present before.
  • You can use single instead of double quotes except in some odd circumstances, such as where the single quotes are in the downstream part of a pipeline, as noted in this SO answer. Yes, this can be exasperating sometimes; you could momentarily set +o histexpand if you can't work around it another way.
  • Thanks for the remark. I added a section emphasizing that there are obviously differences between single and double quotes and included a couple of workarounds.
  • ... or even: echo -e "#\041$SHELL"
  • Best answer on [bash] "event not found" unfortunely not at 1st place
  • For years this is how I've worked around the error message (which I never really understood until today) for one-liners like grep -q pattern somefile.txt && echo "YAY! ". And probably still will, because double-quoting strings in the shell is just in my muscle memory.