Block Comments in a Shell Script
Is there a simple way to comment out a block of code in a shell script?
#!/bin/bash echo before comment : <<'END' bla bla blurfl END echo after comment
' around the
END delimiter are important, otherwise things inside the block like for example
$(command) will be parsed and executed.
Read more... Read less...
There is no block comment on shell script.
vi) you can easily comment from line n to m
(that reads, from line 10 to 100 substitute line start (^) with a # sign.)
and un comment with
(that reads, from line 10 to 100 substitute line start (^) followed by # with noting //.)
vi is almost universal anywhere where there is
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
The following should work for
The blocks of code to be commented can be put inside
[ -z $BASH ] || shopt -s expand_aliases alias BEGINCOMMENT="if [ ]; then" alias ENDCOMMENT="fi" BEGINCOMMENT echo "This line appears in a commented block" echo "And this one too!" ENDCOMMENT echo "This is outside the commented block"
Executing the above code would result in:
This is outside the commented block
In order to uncomment the code blocks thus commented, say
alias BEGINCOMMENT="if : ; then"
alias BEGINCOMMENT="if [ ]; then"
in the example above.
if you can dodge the single quotes:
__=' blah blah comment. '