[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: $? is -1
From: |
Stephane Chazelas |
Subject: |
Re: $? is -1 |
Date: |
Fri, 5 Jul 2019 19:03:16 +0100 |
User-agent: |
NeoMutt/20171215 |
2019-07-05 09:03:06 -0400, Chet Ramey:
[...]
> > Second, when ran in a subshell, the same exit status gets mapped to 255.
> > While logical, as -1 gets mapped to 255, it seems inconsistent.
> > ( from the manual: "The return status is the exit status of list." )
>
> It's the difference between passing a status around the shell and passing
> it through the waitpid() interface, which takes just eight bits.
[...]
Note though:
$ bash -c 'f() { return "$1"; }; f -1; echo "$?"'
255
It gets mapped to 255 even though there's no waitpid().
bash also takes upon itself to truncate the number passed to
exit(1) before passing it to _exit(2):
$ strace -fe exit_group bash -c 'exit -1'
exit_group(255) = ?
There's a lot of variation between shells (and other utilities)
on that front. See also:
https://unix.stackexchange.com/questions/418784/what-is-the-min-and-max-values-of-exit-codes-in-linux/418802#418802
https://unix.stackexchange.com/questions/99112/default-exit-code-when-process-is-terminated/99134#99134
--
Stephane
- $? is -1, bashbug, 2019/07/05
- Re: $? is -1, Chet Ramey, 2019/07/05
- Re: $? is -1,
Stephane Chazelas <=