From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26309 invoked by alias); 9 Mar 2018 22:45:41 -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: List-Unsubscribe: X-Seq: 23225 Received: (qmail 15032 invoked by uid 1010); 9 Mar 2018 22:45:41 -0000 X-Qmail-Scanner-Diagnostics: from mta02.eastlink.ca by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(24.224.136.13):SA:0(-1.9/5.0):. Processed in 11.912559 secs); 09 Mar 2018 22:45:41 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: rayandrews@eastlink.ca X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | MIME-version: 1.0 Content-transfer-encoding: 8BIT Content-type: text/plain; charset=utf-8; format=flowed X-Authority-Analysis: v=2.3 cv=dfKuI0fe c=1 sm=1 tr=0 a=RnRVsdTsRxS/hkU0yKjOWA==:117 a=RnRVsdTsRxS/hkU0yKjOWA==:17 a=IkcTkHD0fZMA:10 a=qC59qy-DRlknsmC5CioA:9 a=7Zwj6sZBwVKJAoWSPKxL6X1jA+E=:19 a=QEXdDO2ut3YA:10 X-EL-IP-NOAUTH: 24.207.101.9 Subject: Re: unmatched ' To: zsh-users@zsh.org References: <2dcec644-7acb-5916-2858-2301206f1da8@eastlink.ca> From: Ray Andrews Message-id: <18dac66c-f348-8123-c051-4deb3dd21294@eastlink.ca> Date: Fri, 9 Mar 2018 14:45:24 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 In-reply-to: Content-language: en-CA On 09/03/18 12:23 PM, Bart Schaefer wrote: > You really should never do this with "eval". Consider what happens if the > file name is /etc/Why you should never `rm -rf /` > > (Obligatory warning: DO NOT TRY THAT AT HOME.) I probably have a lot of improper constructions here, I use the first thing that seems to work, and later I repent of various sins as they become apparent.  How would I best do that sort of thing? > Why are you putting stuff like that file in /etc/ in the first place? Heck, not me!  That's stock Debian, I'd not create a directory like that on pain of damnation.  Debian should not allow it either, IMHO. > If $bar is a file name with spaces in it, $bar will start with a list of directories as originally output by 'find', so whatever my code, it has to handle whatever 'find' might find. > Based on your description there must be a leading "|" in $grepstring. > Don't do that. Yeah:     ccolor=33      # Start with yellow, then blue, magenta, cyan.     for file in "$@"; do         # We colorize the already selected lines here:         grepstring="$grepstring | GREP_COLOR='01;'"$ccolor" grep $wwild $ccase --color=always \"$file\""         (( ccolor++ )) # Next color.     done ... so I'm filtering and colorizing however many arguments there are to the command, so each iteration must (?) begin with the pipe.  And the final string:     bar=(`eval "find -H -O3  / -warn  -type d -ipath \"*$1*\"" $grepstring`) > Assuming you've carefully sanitized $grepstring to avoid gotchas like > unintentional `...` or $(...) substitutions, the closest you should > ever get to what you're doing is > > baz=( `print -lr -- "${bar[@]}" | eval "$grepstring"` ) > > There's probably a better way to do your cascade of greps, too, such > as building a file with one pattern per line and running a single > "grep -f patternfile", but you haven't provided sufficient context. > The $grepstring itself can't have any surprises (famous last words) but the entire construction is of course suspect.  I see you're shrinking the target of eval to the minimum, that seems sensible on first principals but I can't think of a way to get the first pipe outside of $grepstring.  The thing is just to turn a string into a command because the only way I know to create flexible commands is by way of strings. Anyway, is there no way of putting a global protection on nasty characters inside the list of directories?  I'm sure I did read about that, but there's so much to remember. BTW I started doing this sort of cascading colorization with a very similar function I use to explore the history.  I can refine the search with as many strings as I want, and they all show up with different colors, which is even useful, not just eye candy. The final array gets fed to Sebastian's 'n_list' for selection. Quite indispensable to me.