Bash 注釋

2023-01-30 13:41 更新

注釋對于任何編程語言都是不可忽視的重要組成部分,編寫者通過注釋來為其他人提供解釋或提示,能有效提高代碼的可讀性。 Bash 同其他編程語言一樣提供了兩種類型注釋的支持。

  • 單行注釋
  • 多行注釋

Bash 單行注釋

在注釋段落的開頭使用#,如下:

  1. #!/bin/bash
  2. #This is the basic bash script
  3. echo "Hello World!"

將上面的代碼執(zhí)行后,在執(zhí)行命令的過程中會自動忽略注釋部分,不會被解釋輸出

  1. $ ./bath_script.sh
  2. Hello World!

Bash 多行注釋

插入多行注釋有兩種方法:

  1. << BLOCKBLOCK之間的內(nèi)容會被當成注釋。

  1. #!/bin/bash
  2. << BLOCK
  3. This is the basic bash script
  4. This is the basic bash script
  5. BLOCK
  6. echo "Hello World!"
  1. :''之間的內(nèi)容會被當成注釋

  1. #!/bin/bash
  2. : '
  3. This is the basic bash script
  4. This is the basic bash script
  5. '
  6. echo "Hello World!"
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號