Wednesday, December 04, 2024

Block comments in bash

In C/C++, to comment out a block of code, I generally use

 #if 0
 ...stuff
 #endif 

 Or block comment (if there are no other comments)

 /* 
 ...stuff
 */ 

 But there is no such thing in bash, so the common hack is

 : '
 ...stuff
 '
 
i.e., use the : (no-op) operator and then the entire block to be commented goes into a single-quoted string! 

But even more simpler is:

 if false; then
 ... stuff
 fi

 why not!? :=)