Shell script put multiple line comment

by Vivek Gite on July 30, 2007 · 2 comments

Q. I’d like to use multiline comments under shell script. Under C / C++ I can use format

/*
my c code
comment # 2
blah
*/

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

A. By default shell script can be commented out prefixing # character for example:
# my comment
For multilinecomment use
# 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"

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 2 comments… read them below or add one }

1 Ikram May 14, 2011

you can also put multi-line comments using

:’
comment1comment1
comment2comment2
comment3comment3
comment4comment4

Reply

2 Graham Nicholls June 7, 2011

Err, no.
You can’t, at least in bash 4.0.33, which I’m using.

Aha, yes you can, but what is not clear (not your fault, Ikram – just the way the web page displays), is that you need a space between the : and the opening ‘
so:
#!/bin/bash
echo “Hello”
: ‘
comment
comment

echo “Bye”

Works, which is new for me, so thanks!

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 2 + 11 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: