📄 commentblock.sh
字号:
#!/bin/bash# commentblock.sh: <<COMMENTBLOCKecho "This line will not echo."This is a comment line missing the "#" prefix.This is another comment line missing the "#" prefix.&*@!!++=The above line will cause no error message,because the Bash interpreter will ignore it.COMMENTBLOCKecho "Exit value of above \"COMMENTBLOCK\" is $?." # 0# No error shown.echo# The above technique also comes in useful for commenting out#+ a block of working code for debugging purposes.# This saves having to put a "#" at the beginning of each line,#+ then having to go back and delete each "#" later.echo "Just before commented-out code block."# The lines of code between the double-dashed lines will not execute.# ===================================================================: <<DEBUGXXXfor file in *do cat "$file"doneDEBUGXXX# ===================================================================echo "Just after commented-out code block."exit 0####################################################################### Note, however, that if a bracketed variable is contained within#+ the commented-out code block,#+ then this could cause problems.# for example:#/!/bin/bash : <<COMMENTBLOCK echo "This line will not echo." &*@!!++= ${foo_bar_bazz?} $(rm -rf /tmp/foobar/) $(touch my_build_directory/cups/Makefile)COMMENTBLOCK$ sh commented-bad.shcommented-bad.sh: line 3: foo_bar_bazz: parameter null or not set# The remedy for this is to strong-quote the 'COMMENTBLOCK' in line 49, above. : <<'COMMENTBLOCK'# Thank you, Kurt Pfeifle, for pointing this out.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -