Is there a standardized syntax for Linux prognam? [closed]
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this questionOn a Linux system it is typical to type progname --help
in order to view the help output for that program. After this you will see a description like: progname [SWITCHES] [FILES]... [ETC]
My question is; is there a standardized syntax开发者_开发知识库 for his sort of (command-line use) documentation?
In order to describe things like optional switches, multiple parameters (like a file list), switch patterns, etc. It seems like there would be a standard so that anyone who knows it, could accurately interpret your documentation.
Note: This is purely about writing my own documentation, not parsing arguments.
I have browsed many linux man pages and here are a few things that I have seen that seem to be standard to the man pages that come standard with linux. Like some of the above contributors have said, there doesn't appear to be any published documentation standard. I have seen some differences on the web but the pages that come with linux appear to be pretty consistent.
- The command in question appears first.
- Things that are parameters supplied by the user are placed in angle brackets, "<>", with a name given inside the brackets describing what the parameter is. ex.
- Parameters that are optional are placed in square brackets, "[]".
- If a parameter value must be chosen from a defined set then the different options are separated by the pipe symbol, "|", representing "or".
- You can use dot dot dot "..." to simplify a list if it's contents follow a logical progression. ex. [...].
- Careful with the spaces. Spaces separate things so no spaces in the name of single things. Use "filename" or "file_name", not "file name".
That's all I can think of right now. Feel free to add to and correct if you see fit.
The GNU Getopt Library is likely the most standard way to parse arguments now. There are library bindings for most any language you'll be using.
Do you want to implement such help in your program? There are standard Linux commands for this:
getopt - to use in a script http://linuxmanpages.com/man1/getopt.1.php
getopt, getopt_long - to use in C+/C++ http://linuxmanpages.com/man3/getopt.3.php
There is http://www.gnu.org/prep/standards/standards.html#g_t_002d_002dhelp and http://www.gnu.org/prep/standards/standards.html#Option-Table
But i can't see a strict standard definition...
精彩评论