Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Reading output into variables
- X-seq: zsh-workers 32538
- From: Yuri D'Elia <wavexx@xxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: Reading output into variables
- Date: Mon, 07 Apr 2014 18:24:11 +0200
- In-reply-to: <140407084404.ZM8781__34388.9075717472$1396885640$gmane$org@torch.brasslantern.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <lhuc74$rjf$1@ger.gmane.org> <140407084404.ZM8781__34388.9075717472$1396885640$gmane$org@torch.brasslantern.com>
On 04/07/2014 05:44 PM, Bart Schaefer wrote:
> ... it would seem to imply that "program" is a shell construct so it
> doesn't need an extra process in the first place, which leaves a temp
> file as the only answer to your question ... but that probably isn't
> as "convenient" as you want.
My biggest issue with the "| read" built-in is that it doesn't work in
any shell beyond zsh (yes, I should have clarified that more).
Bash will still execute "read" as part of a separate pipeline, and thus
the variables are simply lost.
> } program | { read a b; hooray }
>
> ... which leaves me uncertain as to what "subshell" you were talking
> about in the first example.
In this case of course, we just accumulate more commands in the same
subshell, so that we can temporarily use the values. I quite like the
idiom, as it makes the variables local to pipeline, but that's about it.
> The above "set" solution works in bash. In zsh you could also do
>
> set -A array -- $(program)
>
> to avoid clobbering $1 et al.
Yes, this goes in the direction that I wanted.
Another hack that I was able to use with both bash and zsh is by using a
here-string instead:
read a b <<< $(magic)
In the same line of thought
read a b < <(magic)
also works in bash.
I didn't think of using 'set'. This will work also in plash *sh, though
overwriting $1..N is not convenient, and at least "dash" doesn't support
arrays.
Now I'm left thinking what can I get out of plain ksh...
Messages sorted by:
Reverse Date,
Date,
Thread,
Author