Consider
echo \ # this is a comment
foo
This gives:
$ sh foo.sh
# this is a comment
foo.sh: line 2: foo: command not found
After some searching on the web, I found a solutionby DigitalRoss on sister site superuser. So one can do
echo `: this is a comment` \
foo
or alternatively
echo $(: this is a comment) \
foo
However, DigitalRoss didn't explain why these solutions work. I'd appreciate an explanation. He replied with a comment "There used to be a shell goto command which branched to labels specified like : here. The goto is gone but you can still use the : whatever syntax ... : is a sort of parsed comment now.", but I'd like more details and context, including a discussion of portability.
Of course, if anyone has other solutions, that would be good too.
See also the earlier question How to comment multi-line commands in shell scripts?.