From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11638 invoked by alias); 26 Oct 2015 01:17:52 -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: 20821 Received: (qmail 27314 invoked from network); 26 Oct 2015 01:17:50 -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,HTML_MESSAGE, T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skepticism_us.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=W0VeNbyh6x+W823OUEqkgPNVPjs4N2J5ZXO+RD8M7uA=; b=FTHgDFr5RqgbNEr6HcHYLWMz7s6iUP8XL2et3rXfy1+kHtFePfDKFX4MuA81scmhfA hV0fbIFfRrxIY9Tmx2GhuAcR486rAHOr8eowQgXwCVXuTQzFf12pdrWb+hJDzUobxN8o cVNY2ujTGAULTqSOiHcbFsm8qord8wz3x7fFvpsMQw2+xk9SIxwnoPVw/1Z59Rn1JZoT 62hSYQHBgGfYnY6TcEtLW3aolEKvKTUDbITC62G1awbqrF7CCj73U226e4wN99CXA0A+ IGCmaxnbFyH6EH0pdTa9ftha4P7Ap5ooL0R9B3NAN4blCcnWwzytN448Wz3xX8uedcDR 895w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=W0VeNbyh6x+W823OUEqkgPNVPjs4N2J5ZXO+RD8M7uA=; b=iOce2xmMKil56HWMp4Z5lThrio4RnrOHAJr6Mf3hszuVkucDub0ctRgGqUg9rFSxBP CoNElARd4H8FZCA2k11G//SNqxlYof8M1WeRKZahZBVr0ON/7Sft7UvbWNNhHl/nejlB VGPJHwpAgbZf8fm5pSRpYJun+YXn83kYjqUUUifOAzSMI2RQTiQ9AnuD2HfbcZ/1TFS9 qvSF1X+VHPv8MjWtS4P3ojeo296r08TyjoPUAqqxbUGP4Y1X/1HKT1Zh3ae0NeC+PEQa rS3vOvYosjjxiVNatVTA7vicSUzWWfjPUYQWlrxNXeLS+jeP37PNbuXq/gsN/DiqU61B yfhQ== X-Gm-Message-State: ALoCoQn+gLhDHqERV9+XUi/82ImV418ckhjXw4EtndVyYJEjFJ1fhBEM9pRBSlA/Hpyg1GWXYgjy MIME-Version: 1.0 X-Received: by 10.112.147.10 with SMTP id tg10mr16090253lbb.58.1445822266466; Sun, 25 Oct 2015 18:17:46 -0700 (PDT) In-Reply-To: <151025180235.ZM30558@torch.brasslantern.com> References: <562D31C3.9030705@eastlink.ca> <151025180235.ZM30558@torch.brasslantern.com> Date: Sun, 25 Oct 2015 18:17:46 -0700 Message-ID: Subject: Re: greps pipes and eval bad patterns From: Kurtis Rader To: Zsh Users Content-Type: multipart/alternative; boundary=047d7b3a8ec09a04580522f7ba5c --047d7b3a8ec09a04580522f7ba5c Content-Type: text/plain; charset=UTF-8 On Sun, Oct 25, 2015 at 6: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 do > so, you're on the right track with "eval" -- you just haven't applied > enough quoting.... In addition to what Bart said I'll point out that it's usually easier and safer to avoid the eval by using an if/else block. Getting the quoting right when using eval can be very difficult. Especially if you don't have direct control over the text being eval'd; e.g., if some of it is supplied by the user; or even just built up from earlier parts of the function. I have several functions where 99% of the time I want the output automatically piped into my pager (e.g., /usr/bin/less). But if the output of the function is redirected away from my tty I don't want the pager in the pipeline. So instead of using a variable that would normally contain "| $PAGER" and sometimes be empty (i.e., using Ray's approach) I simply spell it out: if [[ -t 1 ]] ; then grep -h -E $case_insensitive -- "$search_for" $files | $PAGER else grep -h -E $case_insensitive -- "$search_for" $files fi Yes, that introduces some redundancy. But it's far clearer and safer than writing something like this (totally untested): if [[ -t 1 ]] ; then pager='| $PAGER' else pager='' fi eval grep -h -E $case_insensitive -- "$search_for" $files $pager -- Kurtis Rader Caretaker of the exceptional canines Junior and Hank --047d7b3a8ec09a04580522f7ba5c--