Multi-line comments in shell scripts

How to use comments in the shell

1. Single line comment

Single-line comments are the most common, and they are implemented through a '#'. Note that the # sign at the beginning of the shell script "#! / Bin / bash" is not for comments.

2. Multi-line comments

There is also a multi-line comment method in the shell script, which we call the "HERE DOCUMENT" feature. The format is as follows:

<<xxxx
	comment 1
	comment 2 
	啊啊啊啊
xxxx

Where xxxx can be any string. The middle part is a note. This method is often used to indicate the usage of the function, as shown in the following figure:

#########################################################################
# File Name: hereDocument.sh
# Author: sun
# mail: [email protected]
# Created Time: 2020年03月01日 星期日 11时00分27秒
#########################################################################
#!/bin/bash

<<comment
	1. 可以用来多行注释
	2. 常用来描述一个函数的用法说明
	3. 使用任意个字符串括起来就行,不一定是comment
comment

usage(){
#如果添加一个'-',则用来说明忽略行首的制表符
cat <<EOF
	usage:commond [-x] [-v] [-z] [file ...]
	a short explation of the opteration goes here;
	It might be a few lines long, but shouldn't be excessive.
EOF
}

if [ $# -ne 1 ];
then
	usage
	exit 0
fi

length=$1

#生成随机密码
tr -dc A-Za-z0-9_ < /dev/urandom | head -c${length} | xargs

exit
81 original articles published · Liked 69 · Visitors 50,000+

Guess you like

Origin blog.csdn.net/s2603898260/article/details/105525111