Tuesday, July 23, 2013

Commenting some lines of code in Shell/Bash Scripts

To comment a set of lines in a Shell script:
1) Using if false and fi

#!/bin/bash
a=2
if false
then 
b=a
echo a
printf "-------\n"
fi
printf "%d %d\n", a, b


2) Using Comments
#!/bin/bash
a=2
<<COMMENT
b=a
echo a
printf "-------\n"
COMMENT
printf "%d %d\n", a, b

3) Using Search and Replace option

To comment code between lines L1 and L2 we can use
:L1,L2s/^/#/

No comments: