[Toybox] [PATCH] sh: pass "\" to the later app

Chet Ramey chet.ramey at case.edu
Mon Jul 10 07:38:12 PDT 2023


On 7/9/23 7:43 PM, Rob Landley wrote:
> On 6/18/23 16:28, Rob Landley wrote:
>> On 6/12/23 19:40, Chet Ramey wrote:
>>> I wish you were not so reluctant. Look at how many things you've discovered
>>> that I decided were bugs based on our discussions.
>>
>> But since you asked, today's new question I wrestled with was
> 
> What happens when you return from a subshell:

If the subshell is invoked while a function is executing, it's equivalent
to `exit'. Where would it return to otherwise?

> $ (echo one; return;); echo two
> one
> bash: return: can only `return' from a function or sourced script
> two

The shell isn't executing a shell function.

> 
> So in a function, return ends a parenthetical subshell (without error) and
> continues on within the function after the parenthetical (and you can return a
> second time from the same function because the first didn't count),

A subshell is created as an exact copy of its parent -- including the
knowledge that it is executing a shell function -- so `return' is valid.

Since it can't affect it's parent's environment, a return in the subshell
affects only the subshell. Since there are no more commands that the
subshell should execute, it exits.

How would a `return' in the subshell `count' for the parent? How would
you communicate that to the parent, and why would you want to?

  but return
> will NOT end a parenthetical (without error) outside of a function call.

Outside a function call, `return' isn't valid.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet at case.edu    http://tiswww.cwru.edu/~chet/



More information about the Toybox mailing list