zsh-users
 help / color / mirror / code / Atom feed
From: "Lawrence Velázquez" <larryv@zsh.org>
To: Zach Riggle <zachriggle@gmail.com>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: Commenting and large pipelines
Date: Wed, 11 May 2022 03:13:03 -0400	[thread overview]
Message-ID: <6CA29167-7B1F-4E97-966B-4328868CDD15@zsh.org> (raw)
In-Reply-To: <CAMP9c5mWOpVwTpDrrJ4JheYimwcTJRyuoWy9XDdMFJo6eQSb4w@mail.gmail.com>

> On May 11, 2022, at 2:37 AM, Zach Riggle <zachriggle@gmail.com> 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


  reply	other threads:[~2022-05-11  7:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-11  6:34 Zach Riggle
2022-05-11  7:13 ` Lawrence Velázquez [this message]
2022-05-12  6:15 ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6CA29167-7B1F-4E97-966B-4328868CDD15@zsh.org \
    --to=larryv@zsh.org \
    --cc=zachriggle@gmail.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).