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:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop












{ 10 comments… read them below or add one }
you can also put multi-line comments using
:’
comment1comment1
comment2comment2
comment3comment3
comment4comment4
‘
Thanks Ikram…..Its working………
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!
Hey, thanks for those descriptions!!!
Wow, that’s really useful Ikram.
Where did you find that trick? I think O’reilly are going to have to update thier bash pocket reference book!
Greatfull lkram.
Thanks.
Hello:
I have this script and I need to comment out the lines 6, 7, 8. I’ve tried using the # but does not work. Can you help me?
Thanks..
for bash
comment=”
comment1comment1
comment2comment2
comment3comment3
comment4comment4
“
Fantastic tip Ikram..I learnt something new today !!
Many thanks for such a good description!