Comments in Bash
Comments are an essential part of any programming language. It is used to describes the uses of any code or functions. Same as the most of programming language bash scripts also support two types of comments. Single line comment and multi-line comment.
Bash Single Line Comment
Single line comments are started with a hash (#) symbol.
1 2 3 4 5 6 7 | #!/bin/bash # This is a single-line comment echo "Hello World" # This is another single line comment |
Bash Multiple Line Comment
You can also use multi-line comments in bash scripts. There are two ways to do this. Read below example script, shows both ways of multi-line comments.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #!/bin/bash <<COMMENTS This is comment line 1 This is comment line 2 This is comment line 3 COMMENTS echo "Hello World" : ' This is comment line 1 This is comment line 2 This is comment line 3 ' |
The first comment started with <<ANYSTRING and ends with same string ANYSTRING. The second multi line comments started with : '
and ended with single quote '
only.