2012-01-05 95 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