注釋對(duì)于任何編程語(yǔ)言都是不可忽視的重要組成部分,編寫(xiě)者通過(guò)注釋來(lái)為其他人提供解釋或提示,能有效提高代碼的可讀性。 Bash 同其他編程語(yǔ)言一樣提供了兩種類型注釋的支持。
在注釋段落的開(kāi)頭使用#
,如下:
#!/bin/bash
#This is the basic bash script
echo "Hello World!"
將上面的代碼執(zhí)行后,在執(zhí)行命令的過(guò)程中會(huì)自動(dòng)忽略注釋部分,不會(huì)被解釋輸出
$ ./bath_script.sh
Hello World!
插入多行注釋有兩種方法:
<< BLOCK
和BLOCK
之間的內(nèi)容會(huì)被當(dāng)成注釋。#!/bin/bash
<< BLOCK
This is the basic bash script
This is the basic bash script
BLOCK
echo "Hello World!"
:'
和'
之間的內(nèi)容會(huì)被當(dāng)成注釋#!/bin/bash
: '
This is the basic bash script
This is the basic bash script
'
echo "Hello World!"
更多建議: