Multiple line comment in bash / shell script

In bash script, if we want to comment a single line, we just need to add # at the start of the line, like below

#!/bin/bash
# This is a comment
echo "This is printed on terminal"

Now, but in certain scenarios we need to put multiple line comments, like some description of what the script is for, OR just need to disable some section of code / commands from shell script. For doing this, we need to add “<< SOME_TEXT” where we want to start the comment and “SOME_TEXT” after our comment is over. The example of this will look like as below,

#!/bin/bash
<<COMMENT
This is a comment in line no 1
This is a comment in line no 2
This is a comment in line no 3
... and so on ...
COMMENT
echo "This is printed on terminal"

Another way of adding multiline comment using “colon single_quote” to start and “single_quote” to end comment is as below,

#!/bin/bash
#below colon and single quote indicates, multiline comment started
: '
This is a comment in line no 1
This is a comment in line no 2
This is a comment in line no 3
... and so on ...
'
# Above single quote indicates, multiline comment end
echo "This is printed on terminal"
Android Android Commands Android Java Applications Application Libraries Bash / Shell Scripts Bluetooth driver Build Frameworks Commands and Packages Content Management System - CMS Core Kernel C Programs Development Environment Setup Errors & Failures File Systems git Go Language Programs Hardware Platforms Home HTML JAVA Programs Kernel & Device Drivers Kernel Booting and Porting Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL NDK / Middleware / HAL Network Driver OS Concepts PHP Programming Languages RaspberryPi Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Socurce Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Userspace Utilities Web design and development Wordpress Yocto / Bitbake / Openembedded

Leave a Reply