Commenting

How can i comment multiple lines in unix ..............shell script.

Not possible ;

Other than putting your # or ; at the beginning of each line I'm not sure it can be done.

One thought I had is what happens if you use the \ line continuation character. Like this . . .

#my comment starts here \
but is this still considered a comment? \
I'm not sure.

Give that a try in a harmless test script to find out, but it might work.

In bourne, ksh, bash, etc, everything between a # and the newline is ignored. This includes a terminal backslash. But you can have as many comment lines as you want. Just start each one with a #.

There is a kludgy way of doing it

echo "Testing"
: '
echo "This should be ignored"
echo "And so should this"
'
echo "This shouldn't"

i.e. everything between : ' and ' will be ignored. This will fall over if you have single quotes inside the "commented" area.

Cheers
ZB

That actually has side effects that may not be obvious. In the original Bourne shell that was the only way to comment code. If you look at the original csh man page you see:

Bill Joy, the author of csh, explained that he figured a script would always start with a comment and csh used # for comments while sh used : for comments.

The trouble was that : didn't work that well. So Steve Bourne copied the # idea from csh and added it to the Bourne shell. If you follow ZB's syntax exactly, you will sidestep most of the problems that arose from the : comment syntax. These were mostly unintended fd effects like this:
: > /some/important/file
or unintended variable effects like this:
: ${variable:=garbage}

But : is a command and it will succeed. This will set $? and I don't see a way to avoid that. This will work unexpectedly with most sh descendants:

if [ 0 -eq 1 ]
: a harmless comment
then
          echo  whoa
fi

Also there is a performance consideration. The : command cannot be ignored like a # comment can. The arguments to : must be evaluated in case those side effect are desired.

Another way to comment out multiple lines of code is the "here document"
way:

: << --END-COMMENT--
your comment here
--END-COMMENT--

This way, there is no restriction with single quotes. Note that any delimiter
can be used in place of "--END-COMMENT--".
I have tested it It works!!!!