/--- date: 2017-06-02 19:36:36 +0800 categories: 技术 ---/

shell脚本规范

帮助信息格式

注:-h, —help已经成为一个约定俗成的用于显示帮助信息的选项。

Usage: myscript [options] <file...>
Options:
  -v, --version     Show myscript version
  -h, --help        Display this help text
  -d dsn, --dsn=dsn Connect to database "dsn"

# 其中选项(options)和参数(parameters)也有一些约定俗称的规则,如下:
[-c]          May have –c.
{-c foo}      Must have –c with a parameter.
[-abcdef]     May have any of –a ... –f.
[-a | -b]     May have either –a or –b.
{-a | -b}     Must have either –a or –b.
<file>        Must have file as a parameter (not option). 
<file...>     Must have 1+ file parameters.
[file...]     May have 1+ file parameters.

但如果选项很少,仅有几个的情况,可以在第一行里一并写出,示例如下:

Usage: myscript [-vh] [-d dsn] <file...>
Options:
  -v, --version     Show myscript version
  -h, --help        Display this help text
  -d dsn, --dsn=dsn Connect to database "dsn"

退出状态码

0表示成功,非0表示错误

附1:参考