From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9016 invoked by alias); 26 Oct 2015 13:10:19 -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: 20827 Received: (qmail 24042 invoked from network); 26 Oct 2015 13:10:18 -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,FREEMAIL_FROM, T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1445864648; bh=WCveXs7Qs3u2NqopglgkAfG4gpZ7edo16C1Sgaza4WQ=; h=From:To:In-Reply-To:References:Subject:Date; b=EuCCIhQJypccTgumR35j+Xt+CmGlchNG0HIsskCjqOasEu6Gvdir7j/OaD8lhEmFm Q/F8fjxL7X98Ne9LqC17GcAG1njIVbUTM3KIIDNo0F2KkomkpB4u4GuWlRUz8vr+6i odyTYZhdadsBd6UKRDlk+W8sZVnuN2F/KDvl1ydg= From: ZyX To: Ray Andrews , "zsh-users@zsh.org" In-Reply-To: <562D9E85.7080006@eastlink.ca> References: <562D31C3.9030705@eastlink.ca> <151025180235.ZM30558@torch.brasslantern.com> <562D9E85.7080006@eastlink.ca> Subject: Re: greps pipes and eval bad patterns MIME-Version: 1.0 Message-Id: <1413271445864647@web24g.yandex.ru> X-Mailer: Yamail [ http://yandex.ru ] 5.0 Date: Mon, 26 Oct 2015 16:04:07 +0300 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=koi8-r 26.10.2015, 06:32, "Ray Andrews" : > 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 . > } Specifically this I would write as local -a gcmd gcmd=( cat ) if [[ $1 == ,f ]] ; then gcmd=( grep '\[01;34m' ) shift endif integer levels=$(( ($1 + 1) * 4 )) tree --du -haC | grep -Ev '^[^\[]{'"$levels"'\[* ' | $gcmd > > ... a better tree than tree.