Should the usage message which is printed with e.g.
command -?
of a Unix command go to stderr or stdout, and why? Should it go to the same place if the user makes a mistake with an option?
Should the usage message which is printed with e.g.
command -?
of a Unix command go to stderr or stdout, and why? Should it go to the same place if the user makes a mistake with an option?
It should go to stdout, so you can type:
command --help | less
This is also recommended by the Gnu Coding Standards on --help.
On the other hand, the usage message that you get when you use an invalid option or omit a required argument should go to stderr, because it's an error message, and you don't want it to feed into the next command in a pipeline.
When you use --help, the usage message is the normal and expected output of the command. Therefore, it goes to stdout, so it can be piped to another command, like less or grep.
When you say command --bogus-option | other-command, you don't want the usage message going to stdout, because it's now unexpected output that should not be processed by other-command. Also, if the output of --help is more than a handful of lines, then the usage error message should only contain a summary of the --help output, and refer the user to --help for additional details.