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


Groups > gnu.bash.bug > #15081

Re: $? is -1

Path csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail
From Stephane Chazelas <stephane.chazelas@gmail.com>
Newsgroups gnu.bash.bug
Subject Re: $? is -1
Date Fri, 5 Jul 2019 19:03:16 +0100
Lines 32
Approved bug-bash@gnu.org
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>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
X-Trace usenet.stanford.edu 1562349808 6455 209.51.188.17 (5 Jul 2019 18:03:28 GMT)
X-Complaints-To action@cs.stanford.edu
Cc bashbug@jonkmans.nl, bug-bash@gnu.org, bash@packages.debian.org
To Chet Ramey <chet.ramey@case.edu>
Envelope-to bug-bash@gnu.org
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=aETuQ2Su7iK4AOR4Ki0JQmYlCtlRJvNWr0QyvrpP5w4=; b=dz/bzBI2qXsWxAmTsF+xLfs5E9zE/g53C6zslsoF92URNSNXGmBrpxRVZKHO1yE18T Hf0tLssmh4u1k32F1+7oAcMxhIs6ru765Wdvgwf1dCErqhGS7tYA1JvpAgMlAY7r7zC/ 3MRRcxyZXNGxUG9sU4EUwPMgwsxr1o0eaGYKyY6vLaaP7wfrfdw/md9EQGRxTFt4qjdZ exBknLT4iMpvtSGQmmcT0h8PYrorrzDaXde4d9N3xWb4q7TGetWGq0GmXRbZw3YIyO80 EmPeIT6YJ24KnMzAponvKe9XOOi5BqiP/0w75Wyy4xCGr5xYcHMEVJ4kBElUhcp17rqu jbGw==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=aETuQ2Su7iK4AOR4Ki0JQmYlCtlRJvNWr0QyvrpP5w4=; b=ZJXpUDFgXyBftKCrZTElLtlYN3uFriB9g6W6rHc1EYYU8wFtu7dEOJnqWWbwLApiVR Qz7ha7wAgtRF4anzXxhWoPzMJBDtnzZhboytfm+AXH/yYgiNTA0pjlEMPCMADAu5Js7C oaMm/dxUS4qacmV1iPeSWjkNnvHbdQD6sRUtZaCFXHLO5+G9GQNql5q/Qleewwj0Ge3G TlMOGsNwZJ8l8c6uXwRjzp33l8F7+qgimMsi0NXpzmv8ewyLF+MjoinS+GpFbaGerNbl wx12f5ia5CPLFL6gLpIxPLbvzziQlJ4yQ6d47IqfRwz5meIarBgq6QW8c5nxJmQpAVqJ RJmA==
X-Gm-Message-State APjAAAXYdyrmMrU8ia/VXdoi+G0fdfM7eo1vyB6DClvVk6JSn/D25ri4 AWFlh5tc6fBxXtxd4KqLlok=
X-Google-Smtp-Source APXvYqwN8Xai6PvgMxprx7lWpdcQRLJ+aiqiaKFfeaXAkFGr7CV9hfta4oqZ/Ral9Ar5yGyKCZhxZw==
X-Received by 2002:a5d:6b46:: with SMTP id x6mr4978072wrw.122.1562349798745; Fri, 05 Jul 2019 11:03:18 -0700 (PDT)
Content-Disposition inline
In-Reply-To <d8fba239-dd01-b88b-c489-cfcf75ebb0b9@case.edu>
User-Agent NeoMutt/20171215
X-detected-operating-system by eggs.gnu.org: Genre and OS details not recognized.
X-Received-From 2a00:1450:4864:20::441
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 <20190705180316.b7pbekrixjs3m6kc@chaz.gmail.com>
X-Mailman-Original-References <20190705095750.46F0D125555@sint.jonkmans.nl> <d8fba239-dd01-b88b-c489-cfcf75ebb0b9@case.edu>
Xref csiph.com gnu.bash.bug:15081

Show key headers only | View raw


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


Thread

Re: $? is -1 Stephane Chazelas <stephane.chazelas@gmail.com> - 2019-07-05 19:03 +0100

csiph-web