2012-08-15 107 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