dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Harald van Dijk <harald@gigawatt.nl>
To: Dirk Fieldhouse <fieldhouse@gmx.net>,
	DASH mailing list <dash@vger.kernel.org>
Subject: Re: 'return' from subshell in function doesn't
Date: Sun, 8 Mar 2020 13:44:46 +0000	[thread overview]
Message-ID: <98ce2d03-e647-48b2-e4dd-3ceb810f2b24@gigawatt.nl> (raw)
In-Reply-To: <9b3a55fb-df00-8ac3-7a1e-b60e24aa2970@gmx.net>

On 08/03/2020 12:35, Dirk Fieldhouse wrote:
> POSIX
> <https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#return> 
> 
> says, and has since at least 2004:
> "The return utility shall cause the shell to stop executing the current
> function or dot script. If the shell is not currently executing a
> function or dot script, the results are unspecified."
>[...]
> As POSIX refers to subshells explicitly elsewhere (eg 'exit') it's
> difficult to believe that "subshell" was accidentally omitted from the
> list of contexts that 'return' should return from, but implementation
> behaviours consistently contradict the spec as written. Can they be made
> conformant without breaking existing scripts?

In the subshell, the shell should not be considered to still be 
executing a function or dot script. As such, the results should be 
unspecified, and any behaviour should be valid. The standard may be 
underspecified here, but any other interpretation is not reasonable.

Subshells work by starting a new process. The parent process waits for 
the subshell to finish and acts on its exit status. The child process 
has very little ways to influence its parent process other than that, 
and the parent process might not even still be running by the time the 
child process gets to the return statement.

Cheers,
Harald van Dijk

  reply	other threads:[~2020-03-08 13:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <S1726267AbgCHLof/20200308114435Z+1505@vger.kernel.org>
2020-03-08 12:35 ` 'return' from subshell in function doesn't Dirk Fieldhouse
2020-03-08 13:44   ` Harald van Dijk [this message]
2020-03-08 14:40     ` Dirk Fieldhouse
2020-03-08 15:19       ` Harald van Dijk
2020-03-09  7:44         ` Stephane Chazelas
2020-03-09 12:43         ` Dirk Fieldhouse

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=98ce2d03-e647-48b2-e4dd-3ceb810f2b24@gigawatt.nl \
    --to=harald@gigawatt.nl \
    --cc=dash@vger.kernel.org \
    --cc=fieldhouse@gmx.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).