Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #15081
| From | Stephane Chazelas <stephane.chazelas@gmail.com> |
|---|---|
| Newsgroups | gnu.bash.bug |
| Subject | Re: $? is -1 |
| Date | 2019-07-05 19:03 +0100 |
| Message-ID | <mailman.233.1562349808.2688.bug-bash@gnu.org> (permalink) |
| References | <20190705095750.46F0D125555@sint.jonkmans.nl> <d8fba239-dd01-b88b-c489-cfcf75ebb0b9@case.edu> <20190705180316.b7pbekrixjs3m6kc@chaz.gmail.com> |
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 gnu.bash.bug | Previous | Next | Find similar | Unroll thread
Re: $? is -1 Stephane Chazelas <stephane.chazelas@gmail.com> - 2019-07-05 19:03 +0100
csiph-web