When writing bash scripts, any text after a hash sign ( # ) indicates the start of a comment, and any text after # in the same line does not execute. When using a text editor or IDE, comments are colored differently from the rest of the code.
Press CTRL + V to enable visual block mode. Move down and select the lines till you want to uncomment. press x and it will uncomment all the selected lines at once.
A word or line beginning with # causes that word and all remaining characters on that line to be ignored. These lines aren't statements for the bash to execute. In fact, the bash totally ignores them. These notes are called comments. It is nothing but explanatory text about script.
You start your editor, navigate down to the beginning row of the block you want to comment out. You hit i to go into insert mode, enter // to comment, hit ESC to go back to command mode, hit j to navigate down to the next row, and then repeat until all the rows are commented out.
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.
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
.
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
Use : '
to open and '
to close.
For example:
: '
This is a
very neat comment
in bash
'
This is from Vegas's example found here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With