Tutorial :Is there a standardized syntax for Linux prognam? [closed]



Question:

On 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.


Solution:1

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.

  1. The command in question appears first.
  2. 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.
  3. Parameters that are optional are placed in square brackets, "[]".
  4. If a parameter value must be chosen from a defined set then the different options are separated by the pipe symbol, "|", representing "or".
  5. You can use dot dot dot "..." to simplify a list if it's contents follow a logical progression. ex. [...].
  6. 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.


Solution:2

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.


Solution:3

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


Solution:4

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...


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »