bin/124748: [patch] sh(1): sh -c 'exit -1' fails with "Illegal number: -1", instead of exiting with a code of 255

Garrett Cooper gcooper at
Mon Apr 27 02:20:03 UTC 2009

The following reply was made to PR bin/124748; it has been noted by GNATS.

From: Garrett Cooper <gcooper at>
To: Jilles Tjoelker <jilles at>
Cc: bug-followup at
Subject: Re: bin/124748: [patch] sh(1): sh -c 'exit -1' fails with "Illegal 
	number: -1", instead of exiting with a code of 255
Date: Sun, 26 Apr 2009 18:46:43 -0700

 On Sun, Apr 26, 2009 at 7:40 AM, Jilles Tjoelker <jilles at> wrote:
 > Do people actually use 'exit -1' instead of the clearer 'exit 255'? '-1'
 > is not an unsigned integer, so not a posix compliant parameter to the
 > exit special builtin. Even then, sh still aborts a script with a nonzero
 > exit code if exit is used wrongly like this.
 Some people do, but I've since then stopped doing this.
 The question I have is:
 - Is the value of the return code uint8_t?
 - Where in the documentation for sh(1) does it say that it can't be
 <0? Here are all of the relevant documentation items for exit codes I
 could find:
    Command Exit Status
      Each command has an exit status that can influence the behavior of other
      shell commands.  The paradigm is that a command exits with zero for nor-
      mal or success, and non-zero for failure, error, or a false indication.
      The man page for each command should indicate the various exit codes and
      what they mean.  Additionally, the built-in commands return exit codes,
      as does an executed shell function.
      If a command is terminated by a signal, its exit status is 128 plus the
      signal number.  Signal numbers are defined in the header file
      exit [exitstatus]
              Terminate the shell process.  If exitstatus is given it is used
              as the exit status of the shell; otherwise the exit status of the
              preceding command is used.
 Nowhere in the above documentation does it mention valid limits being
 in the set, [0, 128+SIGRTMAX] => [0, 254]. It's merely implied by the
 resources at one's disposal (the source, sys/signal.h, etc).

More information about the freebsd-bugs mailing list