shell脚本——注释(单行注释 多行注释)
生活随笔
收集整理的這篇文章主要介紹了
shell脚本——注释(单行注释 多行注释)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
單行注釋
以"#"開頭的行就是注釋,會被解釋器忽略。
#-------------------------------------------- # 這是一個注釋 # author:菜鳥教程 # site:www.runoob.com # slogan:學的不僅是技術,更是夢想! #-------------------------------------------- ##### 用戶配置區 開始 ##### # # # 這里可以添加腳本描述信息 # # ##### 用戶配置區 結束 #####
多行注釋
? ? [root@J01051386 shell]# cat -n zhushi.sh?? ? ? 1 #!/bin/sh ? ? ?2 trap 'echo "before execute line:$LINENO,"$1"=$1"' DEBUG?? ? ?3 #方法一 ? ? ?4 echo aa ? ? ?5 :<<! ? ? ?6 echo bb ? ? ?7 echo cc ? ? ?8 ! ? ? ?9 echo dd ? ? 10 ? ? 11 #方法二 ? ? 12 echo a ? ? 13 :' ? ? 14 echo b ? ? 15 echo c ? ? 16 ' ? ? 17 echo d ? ? 18 ? ? 19 #方法三 ? ? 20 echo aaa ? ? 21 if false;then ? ? 22 echo bbb ? ? 23 echo ccc ? ? 24 fi ? ? 25 echo ddd ? ? 26 ? ? 27 #方法四 :<<任意字符或者數字 ? ? 28 echo aaaa ? ? 29 :<<# ? ? 30 echo bbbb ? ? 31 echo cccc ? ? 32 # ? ? 33 echo dddd ? ? 34 ? ? 35 #方法五 ? ? 36 echo aaaaa ? ? 37 ((0)) && { ? ? 38 echo bbbbb ? ? 39 echo ccccc ? ? 40 } ? ? 41 echo ddddd | [root@J01051386 shell]# sh -x? zhushi.sh? +{2:} trap 'echo "before execute line:$LINENO,"$1"=$1"' DEBUG ++{4:} echo 'before execute line:4,=' before execute line:4,= +{4:} echo aa aa ++{5:} echo 'before execute line:5,=' before execute line:5,= +{5:} : ++{9:} echo 'before execute line:9,=' before execute line:9,= +{9:} echo dd dd ++{12:} echo 'before execute line:12,=' before execute line:12,= +{12:} echo a a ++{16:} echo 'before execute line:16,=' before execute line:16,= +{16:} ': echo b echo c ' zhushi.sh: line 16: : echo b echo c : command not found ++{17:} echo 'before execute line:17,=' before execute line:17,= +{17:} echo d d ++{20:} echo 'before execute line:20,=' before execute line:20,= +{20:} echo aaa aaa ++{21:} echo 'before execute line:21,=' before execute line:21,= +{21:} false ++{25:} echo 'before execute line:25,=' before execute line:25,= +{25:} echo ddd ddd ++{28:} echo 'before execute line:28,=' before execute line:28,= +{28:} echo aaaa aaaa |
綜上所述:需要在自己編譯環境下,親測每種注釋方法的有效性。
據參考文件中所述,在實際linux環境中測試結果,可能linux版本的區別,并不會所有場景都兼容...、、、、、
trap 'command' DEBUG的調試方式,參考文章shell腳本——調試(-n / -x /-c)
參考鏈接:https://blog.csdn.net/lansesl2008/article/details/20558369/
總結
以上是生活随笔為你收集整理的shell脚本——注释(单行注释 多行注释)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: shell脚本——字符串 数组
- 下一篇: shell脚本——实现简单的功能