2012-01-05 103 views
2

假设我有一个简单的名为sleepScript的bash脚本。有没有办法为sleepScript提供文档/手册,如果我输入命令“man sleepScript”或“help sleepScript”,自定义文档将显示出来。如何为自定义脚本提供自定义文档?

+0

为什么不能打印使用情况如何?使用'getopts'你可以做'script -help'或'script -usage'并打印出整个'usage' – 2012-01-05 21:10:39

回答

3

你可以编写任何你想要记录的手册页。对于简单的脚本,一个--help选项通常就足够了。 manpages是用一个叫做“roff”的旧标记写成的。您可以在此处看到文档的简要说明:http://www.schweikhardt.net/man_page_howto.html

更多文档可以在man(7)中找到。

我通常会发现最简单的方法是采用现有的联机帮助页并将其用作模板。为了让用户在键入“man foo”时查看联机帮助页,必须将manpage放置在manpath的某个位置。默认情况下,这通常是/ usr/share/man。如果未设置$ MANPATH,则使用/etc/manpath.config中的目录。联机帮助页应该有一个扩展名作为其类别,它是一个整数。下面是从男人(1)的映射:

1 Executable programs or shell commands 
    2 System calls (functions provided by the kernel) 
    3 Library calls (functions within program libraries) 
    4 Special files (usually found in /dev) 
    5 File formats and conventions eg /etc/passwd 
    6 Games 
    7 Miscellaneous (including macro packages and convenâ 
     tions), e.g. man(7), groff(7) 
    8 System administration commands (usually only for root) 
    9 Kernel routines [Non standard] 

因此,对于你比如你的文件很可能是/usr/share/man/man1/sleepScript.1

相关问题