Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • thanks for pointing the header file.. tried looking into the documentation of a few utils.. hard time finding the exit codes, seems most will be the stderrs... Commented Jan 22, 2014 at 9:13
  • 7
    errno.h is irrelevant when it comes to exit codes, only error messages. Commented Jan 22, 2014 at 23:41
  • Most programs return exit codes according to the BSD convention, as laid out in sysexits.h. However, some programs do return errnos, and I actually think returning errnos makes the most sense. Unhandled errnos propagate upwards, like exceptions, (the errno stays, functions return e.g., -1 or 0|NULL). Since programs are just functions, albeit functions that are run in a separate address space, it makes sense that a program might wish to continue the errno propagation across the process boundary. Commented Jan 12, 2016 at 0:14
  • 1
    @PSkocik, do you have an example of such a command? errnos are not portable (values not consistent across systems), and there's no portable way to get the err name or message from the value (zsh has a builtin for that). Not to mention that some systems have errnos above 123 that would clash with common special-meaning error codes. Usually, commands print the messages from the errno and return a success/failure exit status. commands are intended for users. functions/system calls are intended for programmers. Commented Sep 7, 2016 at 8:17
  • @StéphaneChazelas I've seen it a couple of times, but not in any well established programs, I have to admit. I've been personally returning errno+1 in my toy system lately ( so that 1 continues to mean "any error") because I think serializing errno's across the process boundary makes better sense than translating according to the BSD convention, as program executions are essentially function invocations, and functions use errno. I use my own last-exit-status decoder in my PROMPT_COMMAND (bash) so I get something like "($numeric_code|$bsd_decoded|$errno_plus_one_decoded)". Commented Sep 7, 2016 at 9:00