Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm developing an application which I'd like to follow the "Unix way."

What should I program it to do in case it is called with no arguments (which makes no practical sense):

  • display an error message
  • display help, or
  • exit silently returning 0 considering the task specified (which is nothing to do) was successfully accomplished?
share|improve this question

2 Answers 2

up vote 7 down vote accepted

That depends what kinds of arguments your application expects. If it processes files, it's traditional to read from standard input and write to standard output if no arguments are specified (example: cat, tee, …). If the application has an interactive mode, start it if no arguments are specified (example: sh, ed). If the application expects an object to work on, show an error message and exit with a non-zero status (example: cp, rm). If the application expects a command, show a usage message and exit with a non-zero status (example: sed, tar).

share|improve this answer

Most common variants:

  • display short version of application help with clause "To view full help type app-name --help";

  • display credits and license;

  • "error: no operation specified (use -h for help)".

share|improve this answer
3  
If the program can read from standard input (something most Unix CLI commands can do), it's also acceptable to simply wait for input. For instance, cat will do this. –  James Sneeringer Apr 9 '12 at 17:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.