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 Application Stack / User Interface Bash / Shell Scripts Commands and Packages Compilation Content Management System - CMS Core Kernel C Programs Development & Build Development Environment Setup Errors & Failures Flutter git Go Language Programs Hardware Platforms HTML JAVA Programs Kernel & Device Drivers Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL Monetization / Google AdSense Multimedia - Audio, Video, Images NDK / Middleware / HAL 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 User Interface Web design and development Wordpress Yocto / Bitbake / Openembedded

Leave a Reply / Ask Question