Shell脚本基础:变量与文档嵌入及代码优化
1. 嵌入文档到Shell脚本
在编写脚本时,为脚本提供格式化的最终用户文档(如手册页或HTML页面)是很有必要的。同时,将代码和文档标记放在同一个文件中,能简化更新、分发和版本控制。
可以使用“什么都不做”的内置命令(冒号)和Here文档将文档嵌入脚本,示例如下:
#!/usr/bin/env bash
# cookbook filename: embedded_documentation
echo 'Shell script code goes here'
# Use a : NOOP and here document to embed documentation,
: <<'END_OF_DOCS'
Embedded documentation such as Perl's Plain Old Documentation (POD),
or even plain text here.
Any accurate documentation is better than none at all.
Sample documentation in Perl's Plain Old Documentation (POD) format adapted from
CODE/ch07/Ch07.001_Best_Ex7.1 and 7.2 in the Perl Best Practices example tarball
"PBP_code.tar.gz".
=head1 NAME
MY~PROGRAM--One-line description here
=head1
超级会员免费看
订阅专栏 解锁全文
1182

被折叠的 条评论
为什么被折叠?



