! The character is used to expand the history of csh style.
If you do not use this function, set +o histexpand (also set +o histexpand as set +H ) disables this behavior. It is disabled for scripting, but often included for interactive use. In such cases, my personal recommendation is to permanently disable it by adding set +o histexpand to your .bash_profile (or .bashrc if you don't have .bash_profile ; it's more complicated than I want to try to fit in in brackets).
As a workaround, you can use single quotes instead of double quotes, bearing in mind, of course, their different semantics. For example, if you need to combine quotation marks with variable interpolation, you can change
echo "#!$SHELL"
in
echo '#!'"$SHELL"
(note the adjacent lines in single and double quotes; after the shell finishes working with it, the quotes will be removed and the line #! will be displayed next to the value of the SHELL variable without spaces between them) or a number of other common workarounds, such as
printf '#!%s\n' "$SHELL"
source share