单行注释
以"#"开头的行就是注释,会被解释器忽略。
#-------------------------------------------- # 这是一个注释 # author:菜鸟教程 # site:www.runoob.com # slogan:学的不仅是技术,更是梦想! #-------------------------------------------- ##### 用户配置区 开始 ##### # # # 这里可以添加脚本描述信息 # # ##### 用户配置区 结束 #####
多行注释
方法一: :<<! #被注释的内容 ! 方法二: :' #被注释的内容 ' 方法三: if false;then #被注释的内容 fi 方法四: :<<任意字符或者数字 #被煮熟的内容 任意字符或者数字 方法五: ((0)) && { #被注释的内容 } | [root@J01051386 shell]# cat -n zhushi.sh 1#!/bin/sh 2trap 'echo "before execute line:$LINENO,"$1"=$1"' DEBUG3#方法一 4echo aa 5:<<! 6echo bb 7echo cc 8! 9echo dd 10 11#方法二 12echo a 13:' 14echo b 15echo c 16' 17echo d 18 19#方法三 20echo aaa 21if false;then 22echo bbb 23echo ccc 24fi 25echo ddd 26 27#方法四 :<<任意字符或者数字 28echo aaaa 29:<<# 30echo bbbb 31echo cccc 32# 33echo dddd 34 35#方法五 36echo aaaaa 37((0)) && { 38echo bbbbb 39echo ccccc 40} 41echo 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/
版权声明:本文为weixin_42167759原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。