[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Optimising cat in pipelines
From: |
Lawrence Velázquez |
Subject: |
Re: Optimising cat in pipelines |
Date: |
Thu, 21 Nov 2024 12:42:19 -0500 |
On Thu, Nov 21, 2024, at 12:55 AM, Dave Jennings wrote:
> [[ $filter_option=reverse ]] && filter_fn=rev
> [[ $output_option=start-only ]] && output_fn=head
As an aside, these [[...]] commands always succeed because they
treat their contents as a single nonnull operand. They don't
recognize the "=" operand unless it is surrounded by whitespace:
$ var=foo
$ [[ $var=bar ]]; echo "$?"
0
$ [[ $var = bar ]]; echo "$?"
1
> My question is, does bash do any optimisation if it sees:
>
> input | cat | output
>
> Does it optimise the cat (and one of the pipes) away?
As Greg already said, this is not done.
> I'm guessing not but it would be very nice if it did.
Such an optimization would be unsafe because bash can't know for
sure that cat merely passes data through. It could be a wrapper
script, a loadable builtin, a function, or literally anything.
--
vq