Shell Script - block comment

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
Julio Batista Silva
Data Engineer

I’m a computer engineer passionate about science, technology, photography, and languages. Currently working as a Data Engineer in Germany.

comments powered by Disqus