[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Not to set PIPESTATUS unless necessary
From: |
Peng Yu |
Subject: |
Re: Not to set PIPESTATUS unless necessary |
Date: |
Wed, 8 May 2024 22:34:48 -0500 |
On Wed, May 8, 2024 at 9:23 PM Kerin Millar <kfm@plushkava.net> wrote:
>
> On Thu, 9 May 2024, at 2:57 AM, Peng Yu wrote:
> > Hi,
> >
> > true | true
> > false
> > echo ${PIPESTATUS[@]}
> >
> > In the above commands, echo will print 1. But such information is also
> > available in $?. Therefore, I think it is unnecessary to set
> > PIPESTATUS after false. It is better to preserve its value until it is
>
> Bear in mind that "false" is also a foreground pipeline there.
>
> > really necessary. Otherwise, users will have to preserve PIPESTATUS
> > after running true | true. This will result in more code to write.
>
> Can you show a realistic program in which it necessitates significantly more
> code?
Here is a reasonably real application.
curl url | jq something || {
pipestatus=(${PIPESTATUS[@]})
# A few lines of code to consolidate the exit statuses of curl and jq
into a single exit statute of the pipeline.
}
curl has many exit statuses. jq also has several exit statuses. It
requires a few lines of code to preserve all the exit status info from
both programs. Thus, not having to save PIPESTATUS to pipestatus will
make the above scenario more compact and more readable.
When similar pipelines are used a lot, it would save a lot of
redundant code for not having to save PIPESTATUS.
> >
> > Is there already a switch to turn on the behavior that I suggested? If
> > not, can this feature be added?
>
> There exists no such switch.
>
> --
> Kerin Millar
>
--
Regards,
Peng
- Not to set PIPESTATUS unless necessary, Peng Yu, 2024/05/08
- Re: Not to set PIPESTATUS unless necessary, Kerin Millar, 2024/05/08
- Re: Not to set PIPESTATUS unless necessary,
Peng Yu <=
- Re: Not to set PIPESTATUS unless necessary, Koichi Murase, 2024/05/08
- Re: Not to set PIPESTATUS unless necessary, Koichi Murase, 2024/05/08
- Re: Not to set PIPESTATUS unless necessary, Chet Ramey, 2024/05/09
- Message not available
- Message not available
- Re: Not to set PIPESTATUS unless necessary, Peng Yu, 2024/05/18
- Re: Not to set PIPESTATUS unless necessary, Andreas Kähäri, 2024/05/18
- Re: Not to set PIPESTATUS unless necessary, Peng Yu, 2024/05/18
- Re: Not to set PIPESTATUS unless necessary, Andreas Kähäri, 2024/05/18
- Re: Not to set PIPESTATUS unless necessary, Peng Yu, 2024/05/18
- Re: Not to set PIPESTATUS unless necessary, Lawrence Velázquez, 2024/05/18