2012-08-15 104 views
1

我知道C++中的boost::program_options,它使我幾乎可以立即編寫用戶友好的命令行選項。以「用戶友好」我的意思是,短期和長期的選擇和描述的幫助命令,將類似於此:我必須找到了,這是真的尷尬在bash與內置用戶友好的命令行選項

Copy standard input to each FILE, and also to standard output. 

    -a, --append    append to the given FILEs, do not overwrite 
    -i, --ignore-interrupts ignore interrupt signals 
     --help  display this help and exit 
     --version output version information and exit 

至於我自己在getopts只支持短期選項。這是正確的還是我錯了?

您將如何實現用戶友好的命令行選項?如果你知道任何鏈接,最佳實踐或深度教程,我將非常感激。

+0

'/ usr/bin/getopt' – 2012-08-15 22:55:54

+0

請參閱:http://stackoverflow.com/questions/402377/using-getopts-in-bash-shell-script-to-get-long-and-short-command-行選項 – pb2q 2012-08-15 23:14:22

回答

1

GNU getopt支持很長的選項,可以在任何Bourne-like或csh-like shell中使用。 ksh93的內置getopts也支持長期選項。 zsh有一個zparseopts。

有一個POSIX殼實現getopts的(作爲外殼的功能),在http://stchaz.free.fr/getopts_long.sh