Block Comments in a Shell Script
Is there a simple way to comment out a block of code in a shell script?
Solution 1:
In bash:
#!/bin/bash
echo before comment
: <<'END'
bla bla
blurfl
END
echo after comment
The '
and '
around the END
delimiter are important, otherwise things inside the block like for example $(command)
will be parsed and executed.
For an explanation, see this and this question.
Solution 2:
There is no block comment on shell script.
Using vi
(yes, vi
) you can easily comment from line n to m
<ESC>
:10,100s/^/#/
(that reads, from line 10 to 100 substitute line start (^) with a # sign.)
and un comment with
<ESC>
:10,100s/^#//
(that reads, from line 10 to 100 substitute line start (^) followed by # with noting //.)
vi
is almost universal anywhere where there is /bin/sh
.
Solution 3:
Use : '
to open and '
to close.
For example:
: '
This is a
very neat comment
in bash
'
This is from Vegas's example found here
Solution 4:
You can use:
if [ 1 -eq 0 ]; then
echo "The code that you want commented out goes here."
echo "This echo statement will not be called."
fi