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

Re: greps pipes and eval bad patterns



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.  "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.  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"
  }



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