Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
exit
bash: exit: 1.234: numeric argument required

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

# exit -1
exit

$ echo $?
255   //this is okay
share|improve this question
up vote 3 down vote accepted

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.

WEXITSTATUS(stat_val)

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
4.1.10(4)-release

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

bash$ exit 2
exit
$ echo $?
2

bash$ exit -2
exit
$ echo $?
254
share|improve this answer
    
thanks Darren..... – P K Dec 29 '11 at 9:15

This is specific to your bash version. 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).

share|improve this answer
    
thanks......... – P K Dec 29 '11 at 9:15
1  
Other than a few exit codes, exit codes are not standardized. Also 0 means success, > 0 means some sort of failure. – fpmurphy1 Dec 29 '11 at 14:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .