Shell Script - block comment

Jul 23, 2011·
Julio Batista Silva
Julio Batista Silva
· 1 min read

In Shell script, we can comment line by line using #. It works similarly to // in C++ and identically to # in Python:

# Commented line 1
# Commented line 2
Code # Half commented line 3

To comment multiple lines, like /* */ in C, we do it as follows:

: '
Linha1 comentada
Linha2 comentada
Linha3 comentada
'

The comment block ends as soon as it finds the next apostrophe, meaning your comment cannot contain '. For such cases, we use something called Here document, which works as follows:

:<< '--ALGUM-DELIMITADOR--'
Linha1 comentada
Linha2 comentada
Linha3 comentada
--ALGUM-DELIMITADOR--

Notice that I put the label --SOME-DELIMITER-- in quotes, because if I didn’t, some commented commands would also be evaluated.

Julio Batista Silva
Authors
Senior Cloud Developer
comments powered by Disqus