shell注释
注释对于任何编程语言都是不可忽视的重要组成部分,编写者通过注释来为其他人提供解释或提示,能有效提高代码的可读性。 Bash 同其他编程语言一样提供了两种类型注释的支持。
- 单行注释
- 多行注释
一、Bash 单行注释
在注释段落的开头使用 # ,如下:
#!/bin/bash
#This is the basic bash script
echo "Hello World!"
将上面的代码执行后,在执行命令的过程中会自动忽略注释部分,不会被解释输出
$ ./bath_script.sh
Hello World!
二、Bash 多行注释
插入多行注释有两种方法:
1.在 << BLOCK 和 BLOCK 之间的内容会被当成注释。
#!/bin/bash
<< BLOCK
This is the basic bash script
This is the basic bash script
BLOCK
echo "Hello World!"
2.在 :' 和 ' 之间的内容会被当成注释
#!/bin/bash
:'
This is the basic bash script
This is the basic bash script
'
echo "Hello World!"