In addition to the examples by DigitalRoss, here's another form that you can use if you prefer $()
instead of backticks `
echo abc $(: comment) \
def $(: comment) \
xyz
Of course, you can use the colon syntax with backticks as well:
echo abc `: comment` \
def `: comment` \
xyz
The reason $(#comment)
doesn't work is because once it sees the #
, it treats the rest of the line as comments, including the closing parentheses: comment)
. So the parentheses is never closed.
Backticks parse differently and will detect the closing backtick even after a #
.