From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15213 invoked from network); 19 Aug 2004 17:19:02 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 19 Aug 2004 17:19:02 -0000 Received: (qmail 59173 invoked from network); 19 Aug 2004 17:18:56 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 19 Aug 2004 17:18:56 -0000 Received: (qmail 16449 invoked by alias); 19 Aug 2004 17:18:13 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7887 Received: (qmail 16439 invoked from network); 19 Aug 2004 17:18:13 -0000 Received: from unknown (HELO a.mx.sunsite.dk) (130.225.247.88) by 130.225.247.90 with SMTP; 19 Aug 2004 17:18:13 -0000 Received: (qmail 57469 invoked from network); 19 Aug 2004 17:16:14 -0000 Received: from unknown (HELO moonbase.zanshin.com) (167.160.213.139) by a.mx.sunsite.dk with SMTP; 19 Aug 2004 17:16:12 -0000 Received: from toltec.zanshin.com (toltec.zanshin.com [64.84.47.166]) by moonbase.zanshin.com (8.12.11/8.12.11) with ESMTP id i7JHGAVt020257 for ; Thu, 19 Aug 2004 10:16:10 -0700 Date: Thu, 19 Aug 2004 10:16:10 -0700 (PDT) From: Bart Schaefer Reply-To: zsh-users@sunsite.dk To: Zsh-users List Subject: Re: Tip of the day: previous command output In-Reply-To: <20040819164250.GA21575@spiegl.de> Message-ID: References: <20040819085812.GL22962@localhost> <20040819164250.GA21575@spiegl.de> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, hits=-1.5 required=6.0 tests=BAYES_01 autolearn=no version=2.63 X-Spam-Hits: -1.5 On Thu, 19 Aug 2004, Andy Spiegl wrote: > So I modified Barts "keep" to use > kept=$($*) Unless you also dropped the alias that prefixes keep with noglob, you still need $~*, and to make it an array you probably want kept=( $($~*) ) > So that I can do > keep locate -i pictures | grep -i thursday | grep -i png I don't know whether you intended this, but [with your original edit] that's equivalent to kept=$(locate -i pictures) print -Rc - $kept | grep -i thursday | grep -i png whereas I would guess that, rather, you meant kept=( $(locate -i pictures | grep -i thursday | grep -i png) ) There's no provision -- except via a zmodload'd module -- for creating a user-defined "precommand modifier" like (say) "time" or "coproc" that syntatically consumes an entire pipeline. You'd have to use [inside "keep"] kept=( $(eval $*) ) [in this case NOT $~*] and write keep locate -i pictures \| grep -i thursday \| grep -i png An alternative is to write "keep" this way: keep() { kept=() kept=( $~* ) if [[ ! -t 0 ]]; then while read line; do kept+=( $line ) done fi print -Rc - $kept } Then you can write locate -i pictures | grep -i thursday | grep -i png | keep and thanks to the magic of zsh running the last command of a pipe in the current shell when that command is a function or builtin, you get what you want in $kept.