How to Make Block Comments in Bash
The aim of this pageđź“ť is to explain block commenting in Bash and Python. Making these notes during my read through the intricate Testing and Branching chapter of the Advanced Bash Scripting e-book.
1 min readApr 22, 2024
- In Bash, there is no official block comment syntax, but you can use a no-op command in combination with here document as a workaround.
- When in doubt, check Explaining heredocs in Bash — combined with stream redirection
- Example of a block comment in Bash:
: <<'COMMENT'
This is a block comment.
You can write multiple lines here without affecting the script.
COMMENT
- Python supports block comments using triple quotes for multi-line comments.
- Example of a block comment in Python:
'''
This is a block comment.
You can write multiple lines here without affecting the script.
''
- Bash does not have a built-in block comment feature like Python.
- Python’s block comment syntax is more straightforward and directly supported.