上次写了shell脚本的注释,没想到那么多人的需要,也存在不少不足。这次做个补充吧。
单行注释:
单行注释就比较简单了,直接在行最前端加上符号 # 即可。具体用法如下所示:
# this is comment test echo "this is comment test"
运行结果:
➜ comment git:(master) ✗ sh comment.sh this is comment test
多行注释:
多行注释有很多方法,这里就列举几个常用的
1 eof截止符
eof截止符不但可以用作后续输入命令,还可以用作注释,常用用法:开始注释部分:输入::<<eof 结束部分:eof
具体示例如下所示:
1 # echo is test 2 echo "test" 3 echo "test" 4 echo "test" 5 echo "test" 6 echo "test" 7 :<<eof 8 echo "comment" 9 echo "comment" 10 echo "comment" 11 echo "comment" 12 echo "comment" 13 echo "comment" 14 eof
运行结果:
➜ comment git:(master) ✗ bash comment.sh
test
test
test
test
test
2 感叹号
!号一般作为嵌入内容部分,可以用作注释,常用用法:开始注释部分:输入::<<! 结束部分:!
具体示例如下所示:
1 # echo is test 2 echo "test" 3 echo "test" 4 echo "test" 5 echo "test" 6 echo "test" 7 :<<! 8 echo "comment" 9 echo "comment" 10 echo "comment" 11 echo "comment" 12 echo "comment" 13 echo "comment" 14 !
运行结果:
➜ comment git:(master) ✗ bash comment.sh
test
test
test
test
test
3 逗号
逗号一般作区分内容,也可以用作注释,常用用法:开始注释部分:输入:: ' 结束部分:' (注意,逗号和冒号之间要加空格)
具体示例如下所示:
# echo is test echo "test" echo "test" echo "test" echo "test" echo "test" : ' echo "comment" echo "comment" echo "comment" echo "comment" echo "comment" echo "comment" '
运行结果:
➜ comment git:(master) ✗ bash comment.sh
test
test
test
test
test
自我感觉,这次写的比较清晰了,希望对你有用。
作者:虚生 出处:https://www.cnblogs.com/dylancao/ 以音频和传感器算法为核心的智能可穿戴产品解决方案提供商 ,提供可穿戴智能软硬件解决方案的设计,开发和咨询服务。 勾搭热线:邮箱:1173496664@qq.com weixin:18019245820 市场技术对接群:347609188 |
![]() |
分类:
shell scripts
标签:
shell
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
2018-11-05 Ubuntu释放磁盘空间的几种常用方法