The exclamation mark has multiple uses in BASH, says google. It also says that in command line a statement like
echo "Hello world!"
would give
bash: !": event not found
. If one writes it like
echo "Hello world! "
, with space after “!”, it is correctly displayed.
I understand that double quotes give literal meaning to almost everything quoted (the textbooks say: except for “$”, “`”, and the escape character). On the other hand, the interpretation of “!” in command line is different from its interpretation in a simple bash script
#!/bin/bash echo "Hello world!"
. No space needed after “!”, and the execution of the one-statement script gives no syntax error. I’m not sure why “!” is interpreted by bash differently on command line (when it points to bash history, as “!!” executes the last command in history, whereas “!” followed by a number executes a specific command from bash history) than in a script in which it appears. Is it “just like that”, i.e. the standard that should not be questioned?
HISTORY EXPANSION
The shell supports a history expansion feature that is similar to the
history expansion in csh. This section describes what syntax features
are available. This feature is enabled by default for interactive
shells, and can be disabled using the +H option to the set builtin com-
mand (see SHELL BUILTIN COMMANDS below). Non-interactive shells do not
perform history expansion by default.
Exactly. Double-quote imply you want variable (and command)
interpolation. That people use them all the time either means they want
that functionality or they are not familiar with the reason for
double-quotes. For literal strings always use single-quotes.
Good luck.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.15 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/