zsh-workers
 help / color / mirror / code / Atom feed
* Re: Reading output into variables
       [not found] ` <140407084404.ZM8781__34388.9075717472$1396885640$gmane$org@torch.brasslantern.com>
@ 2014-04-07 16:24   ` Yuri D'Elia
  0 siblings, 0 replies; only message in thread
From: Yuri D'Elia @ 2014-04-07 16:24 UTC (permalink / raw)
  To: zsh-workers

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...



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-04-07 16:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <lhuc74$rjf$1@ger.gmane.org>
     [not found] ` <140407084404.ZM8781__34388.9075717472$1396885640$gmane$org@torch.brasslantern.com>
2014-04-07 16:24   ` Reading output into variables Yuri D'Elia

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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).