shell 脚本中的注释详解

  上次写了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

  具体示例如下所示:

# echo is test
echo “test”
echo “test”
echo “test”
echo “test”
echo “test”
:<<eof
echo “comment”
echo “comment”
echo “comment”
echo “comment”
echo “comment”
echo “comment”
eof

  运行结果:

➜  comment git:(master) ✗ bash comment.sh
test
test
test
test
test

 

2 感叹号

  !号一般作为嵌入内容部分,可以用作注释,常用用法:开始注释部分:输入::<<! 结束部分:!

  具体示例如下所示:

# 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

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

  自我感觉,这次写的比较清晰了,希望对你有用

shell 脚本中的注释详解

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

栗子博客 软件 shell 脚本中的注释详解 https://www.lizi.tw/soft/16942.html

建筑工地上施工员,闲暇时弄个博客打发时间,

常见问题
  • 1、杰齐1.7仅适用于PHP5.2 2、需Zend支持 3、尽量使用宝塔面板 4、尽量使用Windows 系统,关关对Linux支持不太友好。
查看详情

相关文章

评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务

shell 脚本中的注释详解-海报

分享本文封面