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

Re: Commenting and large pipelines



> On May 11, 2022, at 2:37 AM, Zach Riggle <zachriggle@xxxxxxxxx> wrote:
> What I've discovered is that something like this works out pretty well...
> 
>     { printf "%s\n" a b foo c bar d fizz XfooX XbuzzX } |
>     { grep -E 'foo|bar' } |
>     {
>         # If the user specified '--no-fizz-buzz', remove those entries
>         if (( NO_FIZZ_BUZZ )); then
>             grep -vE 'fizz|buzz'
>         else
>         # Pass through everything
>             cat
>         fi
>     }
> 
> I have a few questions about this construct.
> 
>     1. Am I insane for doing this?
>     2. In what ways is this a terrible idea?

There isn’t anything wrong with (or novel about) using grouped commands as pipeline stages.

(However, in your example the braces in the first two stages are unnecessary and distracting. They make me wonder whether there’s some obscure reason you added them.)

>     3. Is the use of {} better than ()?

I can’t think of a compelling reason to use () other than to force the final stage to run in a subshell. (I believe the other stages run in subshells regardless.)

> Thanks for the attention, just curious what everybody thinks about this abuse of pipelines and conditional logic.

It’s not abuse. It’s entirely valid to use complex commands as pipeline stages.

Now, whether or not that is more legible or maintainable than the alternatives is a different, context-dependent question.

-- 
vq
Sent from my iPhone




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