shell脚本中的多行注释
shell 中注释的使用方法
1、 单行注释
单行注释最为常见,它是通过一个‘#’来实现的。注意shell脚本的最开始部分“#!/bin/bash”的#号不是用来注释的。
2、 多行注释
在shell脚本中还有一种多行的注释方法,我们称之为"HERE DOCUMENT"的特性。格式如下:
<<xxxx
comment 1
comment 2
啊啊啊啊
xxxx
其中xxxx可以为任意的字符串。中间部分则为注释。这种方法经常用来表示函数的用法,如下图所示:
#########################################################################
# File Name: hereDocument.sh
# Author: sun
# mail: 13039040421@163.com
# 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