From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8013 invoked by alias); 7 Apr 2014 16:24:35 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 32538 Received: (qmail 18319 invoked from network); 7 Apr 2014 16:24:28 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_NUMERIC_HELO,SPF_HELO_PASS autolearn=no version=3.3.2 X-Injected-Via-Gmane: http://gmane.org/ To: zsh-workers@zsh.org From: Yuri D'Elia Subject: Re: Reading output into variables Date: Mon, 07 Apr 2014 18:24:11 +0200 Message-ID: References: <140407084404.ZM8781__34388.9075717472$1396885640$gmane$org@torch.brasslantern.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 193.106.183.18 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Icedove/24.4.0 In-Reply-To: <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...