Domanda

I am writing a program in C for x86 Linux. I am wanting to use my own customer exit codes to help the user with debugging problems when the program doesn't execute as expected.

As an example, suppose the program was a command line calculator and I would like to return the following exit codes and document them in the man pages;

  1. Calculation completes and prints results to screen (normal operation) - return 0
  2. Invalid number of operands supplied (syntax error basically!) - return 1
  3. Some other error - return 2
  4. Another error - return 3

I have seen a few pages like this one which make me think I can't return any exit code I like. Is there any official rules (BASH or Linux standard/guideline) I should be following here, apart from 0 == normal exit?

È stato utile?

Soluzione

You can return any integral exit code you like. The BASH scripting guide page you reference just says it could be confusing when debugging something that returns a well-known code for some other reason.

That page also mentions /usr/include/sysexits.h as an attempt to systematize exit codes for C programmers.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top