Re: shell error codes
From: Stephane CHAZELAS (this.address_at_is.invalid)
Date: 11/07/04
- Next message: gregg: "Re: shell error codes"
- Previous message: Stachu 'Dozzie' K.: "Re: shell error codes"
- In reply to: gregg: "Re: shell error codes"
- Next in thread: gregg: "Re: shell error codes"
- Reply: gregg: "Re: shell error codes"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 07 Nov 2004 20:31:30 GMT
2004-11-07, 20:40(+01), gregg:
> Barry Margolin wrote:
>
>> The shell doesn't report error codes, it reports the exit status of
>> programs. These are not standardized, except that 0 means success and
>> anything else is considered failure.
>
> I agree to that when a program is launched by the shell.
> But what of:
>
> gregg@darkstar [0] ~$ ./jkkkl
> bash: No such file or directory
> gregg@darkstar [127] ~$
>
> Here, "127" is for "no such file or directory", i.e "ENOENT"
>
> What I want is to associate those integer values with their errno
> counterpart. Some are C-ANSI defined, others Posix.1 (as I gather from
> manpages).
[...]
See:
http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_09_01
The only standardized exit codes are 126 and 127
SUS> If the execve() function fails due to an error equivalent to
SUS> the [ENOEXEC] error defined in the System Interfaces volume
SUS> of IEEE Std 1003.1-2001, the shell shall execute a command
SUS> equivalent to having a shell invoked with the pathname
SUS> resulting from the search as its first operand, with any
SUS> remaining arguments passed to the new shell, except that the
SUS> value of "$0" in the new shell may be set to the command
SUS> name. If the executable file is not a text file, the shell
SUS> may bypass this command execution. In this case, it shall
SUS> write an error message, and shall return an exit status of
SUS> 126.
[...]
SUS> If the search is unsuccessful, the command shall fail with an
SUS> exit status of 127 and the shell shall write an error message
Even the $? for signal termination are not standardized
SUS> The exit status of a command that terminated because it
SUS> received a signal shall be reported as greater than 128
(in most shells, it's 128+SIGNUM, in ksh93, it's 256+signum)
(anyway the signal values are not standardized).
So, you have, for values of $?
0: no error
126: program returned exit code 126 or execve(2) failed with
ENOEXEC
127: program returned exit code 127 or the command was not
found
128+: program returned exit code >128 or it was terminated by a
signal
255+: program was terminated by a signal (and shell behaves like
ksh93)
-- Stephane
- Next message: gregg: "Re: shell error codes"
- Previous message: Stachu 'Dozzie' K.: "Re: shell error codes"
- In reply to: gregg: "Re: shell error codes"
- Next in thread: gregg: "Re: shell error codes"
- Reply: gregg: "Re: shell error codes"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|