Shell Script Put Multiple Line Comment

I would like to use multiline comments under shell script. Under C / C++ I can use the following format

/*
my c code
comment # 2
blah
foo bar
….
*/

How do I put multi line comment under a shell script?

[donotprint][/donotprint]By default shell script can be commented out prefixing # character, for example:

# my comment goes here
For multiline-comment use the following syntax:
# my comment 1
# my comment 2
# my comment N

However, you can use HERE DOCUMENT feature as follows:

#!/bin/bash
echo "Say Something"
<<COMMENT1
    your comment 1
    comment 2
    blah
COMMENT1
echo "Do something else"

Another option as pointed out by Ikram in the comments section below:

#!/bin/bash
foo=bar
: '
This is a test comment
Author foo bar
Released under GNU 
'
 
echo "Init..."
# rest of script

#!/bin/bash
foo=bar
: '
This is a test comment
Author foo bar
Released under GNU
' echo "Init..."
# rest of script

Please note that the : is shell builtin command. From the bash(1) man page:

: [arguments]
No effect; the command does nothing beyond expanding arguments
and performing any specified redirections. A zero exit code is
returned.

So the syntax is:

: '
 your comments here
'

: '
your comments here
'

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.