How to add comments in Bash Scripts

How to add comments in Bash Scripts

How to add comments in Bash Scripts

1. Single-Line Comments

#!/bin/bash
# This is a comment
echo "Hello, World!"

2. In-Line Comments

#!/bin/bash
echo "Hello, World!" # show "Hello, World!" to screen

3. Multi-line comments

3.1 using # in the beginning of each line

#!/bin/bash

######################################
## This script is used for scanning ##
## local network                    ##
## Licensed under GPL 2.0           ##
######################################

rest of the bash script code

3.2 Colon notation

#!/bin/bash

: '
This is how you can use colon notation
And this line too will be ignored
'
echo "GOODBYE"

3.3 Here document

#!/bin/bash

<<DELIMITER
Comment line 1
Comment line 2
DELIMITER

echo "Hello, World!"

or this

#!/bin/bash

<<COMMENT
This is a multi-line comment using a here document.
You can add as many lines as you want between <<COMMENT and the terminating keyword.
This block won't be executed by the shell.
COMMENT

echo "Hello, World!"

留言

熱門文章