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

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

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,

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

Leave a Comment