From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7007 invoked by alias); 26 Oct 2015 03:31:23 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 20822 Received: (qmail 1590 invoked from network); 26 Oct 2015 03:31:20 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 X-Authority-Analysis: v=2.1 cv=T/C1EZ6Q c=1 sm=1 tr=0 a=Yb8cCOgIQM/f+1S+w5Li9g==:117 a=Yb8cCOgIQM/f+1S+w5Li9g==:17 a=N659UExz7-8A:10 a=I_9lcTuSr97_mk8Ma_wA:9 a=pILNOxqGKmIA:10 Message-id: <562D9E85.7080006@eastlink.ca> Date: Sun, 25 Oct 2015 20:31:17 -0700 From: Ray Andrews User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Icedove/31.7.0 MIME-version: 1.0 To: zsh-users@zsh.org Subject: Re: greps pipes and eval bad patterns References: <562D31C3.9030705@eastlink.ca> <151025180235.ZM30558@torch.brasslantern.com> In-reply-to: <151025180235.ZM30558@torch.brasslantern.com> Content-type: text/plain; charset=windows-1252; format=flowed Content-transfer-encoding: 7bit On 10/25/2015 06:02 PM, Bart Schaefer wrote: > On Oct 25, 12:47pm, Ray Andrews wrote: > } > } test1 () > } { > } gstring=" | grep \[01;34m " > } tree --du -haC | grep -Ev "^[^\[]{$levels}\[*" "$gstring" > } } > > One doesn't normally build up a pipeline that way, but if you must What would be the better way? I'm not wedded to anything, just looking for the appropriate method. > do > so, you're on the right track with "eval" -- you just haven't applied > enough quoting. "eval" is going to re-parse everything, so you need > to quote everyhing to the same depth: > > eval 'tree --du -haC | grep -Ev "^[^\[]{$levels}\[*"' "$gstring" > > The single quotes (before tree and after the levels pattern) keep the > first pipeline (and importantly the double-quotes that are around the > grep pattern) from being interpreted until eval does so. Enlightenment. We freeze all expansions with single quotes until eval sorts it all out in one go. > The use of > the parameter for $gstring has the same effect. > > You might be able to see this better if you assign everything to > variables before eval-ing, e.g. > > test1 () > { > gstring="| grep \[01;34m " > glevels='| grep -Ev "^[^\[]{$levels}\[*"' > tree="tree --du -haC" > eval "$tree" $glevels" "$gstring" Yeah, that's the sort of thing I'm used to doing I just didn't know how to handle the tricky characters. It makes nothing but sense now that I see it. So the final product becomes: t () { local gstring= [ "$1" = ',f' ] && { gstring=' | grep "\[01;34m" '; shift } integer levels=$(( ($1 + 1) * 4 )) eval ' tree --du -haC | grep -Ev "^[^\[]{$levels}\[*" ' $gstring du -sh . } ... a better tree than tree.