Home » Scripting and Automation » Bash / Shell Scripts » Single and Multi-Line comment in Shell Script

Single and Multi-Line comment in Shell Script

Comments doesn’t add any logical value to the software but those are unavoidable part of the program since those helps to understand actual purpose why this software has been written.

Single Line Comments in 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"

Multi-Line Comments in Shell Script

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,

[bash]
#!/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"
[/bash]

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"

Subscribe our Rurban Life YouTube Channel.. "Rural Life, Urban LifeStyle"

Leave a Comment