Skip to content
Home » Shell Script » How to Comment Out a Huge Block of Shell Code

How to Comment Out a Huge Block of Shell Code

You might want to comment out some lines of shell script code during debug-time, you can just add a pound sign # to the head of each line like this:
$ vi simple_code.sh
#!/bin/bash
line 1
line 2
#line 3
#line 4
line 5
line 6

In the above code, line 3 and 4 are commented out, it's an easy and simple work. But what if the block of code that are going to be commented out is more than hundreds of lines, it could cost you hours to finish it.

Here I introduce a more convenient way to do it, just comment out hundreds of lines by enclosing them in one never-used function block.
$ vi hundreds_code.sh
#!/bin/bash
line 1
line 2
NEVER_USED()
{
line 3
...
line 235
}

line 256
line 257

Once you have finished debugging, just uncomment the block by removing the function declaration and the pair of curly brackets.

Leave a Reply

Your email address will not be published. Required fields are marked *