Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

greps pipes and eval bad patterns


test1 ()
    gstring=" | grep \[01;34m "
    tree --du -haC | grep -Ev "^[^\[]{$levels}\[*" "$gstring"

That's a cut down version of my 'tree' wrapper. If $gstring is appended as it's literal content (as opposed to the variable itself) it works fine, but if I use the variable as shown , grep tries to eat it as part of it's own argument string. I've solved problems like that elsewhere by using 'eval' however it doesn't work in the above situation because eval complains about the contents of the first grep search:

(eval):1: bad pattern: ^[^[]{12}[*

As a point of principal can this be done? The thing would be to stop $gstring from being interpreted as an argument to the first grep and I'm betting it's easy if you know how. In practice my wrapper uses two separate lines, one with and one without the " | grep \[01;34m " (Which, BTW, selects directories only for display based on the color of the output of 'tree'--blue for directories.) But it would be elegant to use one line, and append $gstring (set to null or to the above depending on whether I want directories only as the output, or not.)

Messages sorted by: Reverse Date, Date, Thread, Author