# is not always a comment symbol in Bash
When I started using Nix, mainly for temporary development environments, I
noticed something unexpected: # in some shell commands was treated like a
“normal” character. I always thought # would mark the start of a comment, but
that’s not always the case.
Here’s an example of # working as a comment symbol:
$ echo Hello # World
Hello
And here’s how you use it as a non-comment symbol:
$ echo Hello#World
Hello#World
Mind-blowing, isn’t it?
So I went to check Bash’s man page:
[…] a word beginning with
#introduces a comment. A word begins at the beginning of a line, after unquoted whitespace, or after an operator. The comment causes that word and all remaining characters on that line to be ignored. […]
That’s interesting! Only a word beginning with # starts a comment. That’s
different from other programming languages. For example, in Python any # not
inside a string starts a comment, no leading whitespace required.
Bash always amazes me with its quirks.