Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15082

Re: $? is -1

Path csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail
From Mike Jonkmans <bashbug@jonkmans.nl>
Newsgroups gnu.bash.bug
Subject Re: $? is -1
Date Sat, 6 Jul 2019 00:35:28 +0200
Lines 54
Approved bug-bash@gnu.org
Message-ID <mailman.263.1562366136.2688.bug-bash@gnu.org> (permalink)
References <20190705095750.46F0D125555@sint.jonkmans.nl> <d8fba239-dd01-b88b-c489-cfcf75ebb0b9@case.edu> <20190705180316.b7pbekrixjs3m6kc@chaz.gmail.com> <20190705223528.GA15187@sint.jonkmans.nl>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
X-Trace usenet.stanford.edu 1562366137 15974 209.51.188.17 (5 Jul 2019 22:35:37 GMT)
X-Complaints-To action@cs.stanford.edu
Cc Chet Ramey <chet.ramey@case.edu>, bug-bash@gnu.org, bash@packages.debian.org
To Stephane Chazelas <stephane.chazelas@gmail.com>
Envelope-to bug-bash@gnu.org
Content-Disposition inline
In-Reply-To <20190705180316.b7pbekrixjs3m6kc@chaz.gmail.com>
X-SourceIP 62.163.69.112
X-Ziggo-spambar /
X-Ziggo-spamscore 0.0
X-Ziggo-spamreport CMAE Analysis: v=2.3 cv=bcYVr9HB c=1 sm=1 tr=0 a=ONQKbMlQgRqYTzjcV855Rg==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=kj9zAlcOel0A:10 a=0o9FgrsRnhwA:10 a=pGLkceISAAAA:8 a=mDV3o1hIAAAA:8 a=xNf9USuDAAAA:8 a=Ye9q-bpsAAAA:8 a=HKUaVqmwRO6gkOrR1NEA:9 a=CjuIK1q_8ugA:10 a=_FVE-zBwftR9WsbkzFJk:22 a=SEwjQc04WA-l_NiBhQ7s:22
X-Ziggo-Spam-Status No
X-detected-operating-system by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From 212.54.34.164
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.23
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <https://lists.gnu.org/archive/html/bug-bash>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
X-Mailman-Original-Message-ID <20190705223528.GA15187@sint.jonkmans.nl>
X-Mailman-Original-References <20190705095750.46F0D125555@sint.jonkmans.nl> <d8fba239-dd01-b88b-c489-cfcf75ebb0b9@case.edu> <20190705180316.b7pbekrixjs3m6kc@chaz.gmail.com>
Xref csiph.com gnu.bash.bug:15082

Show key headers only | View raw


On Fri, Jul 05, 2019 at 07:03:16PM +0100, Stephane Chazelas wrote:
> Date: Fri, 5 Jul 2019 19:03:16 +0100
> From: Stephane Chazelas <stephane.chazelas@gmail.com>
> To: Chet Ramey <chet.ramey@case.edu>
> Cc: bashbug@jonkmans.nl, bug-bash@gnu.org, bash@packages.debian.org
> Subject: Re: $? is -1
> 
> 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.
That is true, but the manual states that the return status is the exit status of the list.
But the exit status (-1) and the return status (255) are not equal.
> [...]
> 
> Note though:
> 
> $ bash -c 'f() { return "$1"; }; f -1; echo "$?"'
> 255
> 
> It gets mapped to 255 even though there's no waitpid().

This is a funny one. So bash tries to keep $? between 0..255 in this case.

> 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
I had found that too; it says Posix doesn't specify behaviour of builtin exit called with values outside 0..255 
And that bash truncates to 8 bit.
Posix probably doesn't specify the behaviour because there is no common ground between shells.

I would suggest bash always has its $? values between 0..255 (or at least non-negative)

> https://unix.stackexchange.com/questions/99112/default-exit-code-when-process-is-terminated/99134#99134

Missed that one. Thanks.
> 
> -- 
> Stephane

-- 
Mike Jonkmans <bashbug@jonkmans.nl>

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

Re: $? is -1 Mike Jonkmans <bashbug@jonkmans.nl> - 2019-07-06 00:35 +0200

csiph-web