I have a simple bash script called foo.sh like this:
#!/bin/bash
echo "Foo!"
When I run it as ./foo.sh
I get the Foo!
message and everything's fine.
But if I echo "Foo!"
directly from the console, then I obtain the expected behavior and message: bash: !": event not found
.
I understand that the !
is presented as a previous command and if used inside p.e. single quotes, then it's considered as a literal.
I'm just wondering what is the difference here that running a script with that echo "Foo!"
(even with source ./foo.sh
works but directly from the console it doesn't.
"foo!"
, where the bang is at the end of a quoted string. – ilkkachu Apr 07 '21 at 13:35"foo!"
and maybe some other similar ones. – ilkkachu Apr 07 '21 at 22:52