As per definition exit code 128 means 'invalid exit argument'. But i always get 255 (Exit status out of range) in case argument is invalid like float number.

Is this the proprietary implementation on my linux distribution?

# exit 1.234
bash: exit: 1.234: numeric argument required

$ echo $?
255   //this should be 128?

# exit -1

$ echo $?
255   //this is okay

There is nothing within Bash documentation that says 128 is the required invalid exit code.

Bash itself returns the exit status of the last command executed, unless a syntax error occurs, in which case it exits with a non-zero value.

The last command is the bash builtin exit (from man page)

exit [n]

Cause the shell to exit with a status of n. If n is omitted, the exit status is that of the last command executed.

Checked specification for WEXITSTATUS.


If the value of WIFEXITED(stat_val) is non-zero, this macro evaluates to the low-order 8 bits of the status argument that the child process passed to _exit() or exit(), or the value the child process returned from main().

So exit is restricted to an 8 bit integer ( 0 - 255 ), so -1 would be 255. Exit only understands an integer argument and not floats, so it's likely kicking out a default -1.

bash$ echo $BASH_VERSION

bash$ exit foo
bash: exit: foo: numeric argument required
$ echo $?    

bash$ exit 2
$ echo $?

bash$ exit -2
$ echo $?

This is specific to your shell variant. This http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_08 or http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#exit do not confirm your impression that 128 is some special exit code.

For exit 3.45 my versions of ksh and zsh return 3, tcsh returns 1 (does not actually exit), and ash returns 2 (but also does not actually exit).

  • 1
    Other than a few exit codes, exit codes are not standardized. Also 0 means success, > 0 means some sort of failure. – fpmurphy Dec 29 '11 at 14:13

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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