Shell Script - block comment

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

In shell scripts we can comment line by line using #. It works much like // in C++ and exactly like # in Python:

# Line1 commented out
# Line2 commented out
Code # Line3 half commented out

To comment out several lines, the way /* */ does in C, we do the following:

: '
Line1 commented out
Line2 commented out
Line3 commented out
'

The comment block ends as soon as the next apostrophe shows up, which means your comment cannot contain a '. For those cases we use something called a Here document, which works like this:

:<< '--SOME-DELIMITER--'
Line1 commented out
Line2 commented out
Line3 commented out
--SOME-DELIMITER--

Note that I put the label --SOME-DELIMITER-- in quotes, because without them some of the commented commands would still be evaluated.

Julio Batista Silva
Authors
Senior Cloud Developer

I’m a Brazilian computer engineer based in Germany, passionate about tech, science, photography, and languages.

I’ve been programming for about two decades already, exploring everything from mobile apps and web development to machine learning. These days I focus on cloud SRE and data engineering.

I volunteer in the open source and Python communities, helping organize PyCon DE and PyData Berlin, mentoring, and contributing with code and translations.

On my blog, I share Linux tips, setup guides, and personal notes I’ve written for future reference. I hope others find them helpful as well. The content is available in multiple languages.

Browse my gallery for some of my photography.

Away from the keyboard, you’ll find me at concerts, playing clarinet, cycling, scuba diving, or exploring new places, cultures, and cuisines.

Always happy to connect! 🙂

comments powered by Disqus