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 solution by DigitalRoss on sister site Stack Overflow. 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. Thegoto
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?.
Take home message from the discussion below.
The `: this is a comment`
is just a command substitution.
The output of : this is a comment
is nothing, and that
gets put in the place of `: this is a comment`
.
A better choice is the following:
echo `# this is a comment` \
foo