Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Capturing STDOUT without subshells or file I/O
- X-seq: zsh-users 23669
- From: Oliver Kiddle <okiddle@xxxxxxxxxxx>
- To: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
- Subject: Re: Capturing STDOUT without subshells or file I/O
- Date: Fri, 21 Sep 2018 08:58:20 +0200
- Authentication-results: amavisd4.gkg.net (amavisd-new); dkim=pass (2048-bit key) header.d=yahoo.co.uk
- Cc: robobenklein@xxxxxxxxx, Zsh Users <zsh-users@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1537513102; bh=Yv93mUyGhdM5//n/43jHObJIQEJUZKCgF8WSs2cZBpU=; h=From:References:To:Subject:Date:From:Subject; b=h0dx+k9Z1qrnPlAH3fsmYzOK3ApNlhYOrDLwGo9bUtixOvwvovkVjATyKH+PQD6QT3G0M6XytL0+I04htxiMGmSc3UfMZizdfV2IY4dO++2MYoiztG9NLuAoht14t5LcgQZ6Zt+clZd7MXEUapl4d75rxwRBpnQA5fWAS8tWUacnuP3ABIOzX50CPrHieiunQgQnLt0/BPDugkl5YLFCB6GzBTtM1wZtQiMwSqn00o44UGuFCj0x21LErCpzs44r9QSuBxcqZN9ErR00oZRjWEQLXIoEDde2bnW4uIm6XzrOVjQ7W98uBy0N6zHSQpmM3tvfbITrSAI2y6sqeUFTNQ==
- In-reply-to: <CAKc7PVAxFi0de0odscOMe5h3hP2qjWc2-AOr7kNb=yKxDBpNXw@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <04a12c6a-c926-b088-f386-8a2bdb81dad2@gmail.com> <CAKc7PVAxFi0de0odscOMe5h3hP2qjWc2-AOr7kNb=yKxDBpNXw@mail.gmail.com>
On 18 Sep, Sebastian Gniazdowski wrote:
> > I have an interesting predicament, I with to capture the STDOUT (builtin printf) of a ZSH function to a variable, in which the function should be running in the current shell context.
> mksh can do this with:
>
> ${ foo;}
>
> foo runs in current shell and the ${ ... } is substituted with its
> output.
I was under the impression that ksh93 does this with the basic $( ... )
syntax meaning that that syntax does not inherently imply the use of
a subshell. It depends on whether there are pipes, external commands or
only builtins there.
For ksh93, they had their own I/O abstraction – sfio – which was a
complete replacement for stdio but which made it easy to capture the
output instead of writing it. Using sprintf everywhere would be a
very invasive change but the open_memstream/temporary file approach
used for print -v would work. And in any case, there would be other,
bigger, problems to solve.
Personally, I can't claim to be have ever been especially concerned
about the cost of the fork and was not especially enthused by the
addition of -v to print.
$(...) substitutions are also run sequentially:
echo $SECONDS ; echo $(sleep 1;echo $SECONDS) $(sleep 1;echo $SECONDS)
Perhaps I'm forgetting something obvious but at the moment, I can't
think why they couldn't be run in parallel - if performance is the
concern.
Oliver
Messages sorted by:
Reverse Date,
Date,
Thread,
Author