Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #15081 > unrolled thread
| Started by | Stephane Chazelas <stephane.chazelas@gmail.com> |
|---|---|
| First post | 2019-07-05 19:03 +0100 |
| Last post | 2019-07-05 19:03 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to gnu.bash.bug
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: $? is -1 Stephane Chazelas <stephane.chazelas@gmail.com> - 2019-07-05 19:03 +0100
| From | Stephane Chazelas <stephane.chazelas@gmail.com> |
|---|---|
| Date | 2019-07-05 19:03 +0100 |
| Subject | Re: $? is -1 |
| Message-ID | <mailman.233.1562349808.2688.bug-bash@gnu.org> |
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
Back to top | Article view | gnu.bash.bug
csiph-web