help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: reading from external command


From: Peng Yu
Subject: Re: reading from external command
Date: Tue, 29 Mar 2022 14:07:57 -0500

On 3/29/22, Jesse Hathaway <jesse@mbuki-mvuki.org> wrote:
> On Tue, Mar 29, 2022 at 1:36 PM Peng Yu <pengyu.ut@gmail.com> wrote:
>> Is there a more elegant and efficient way to solve this problem
>> without having to use a tempfile?
>
> lastpipe would allow you use to use PIPESTATUS:
>
> shopt -s lastpipe
> {
> printf '%s\n' a b c
> exit 1
> } |
> while read -r x; do
> results+=("$x")
> done
> declare -p PIPESTATUS
> declare -p results
>
> but, I don't believe there is anyway for the inner loop to
> know about errors from the previous command in the
> pipeline, unless you resort to touching files or use some
> other communication mechanism.

Could shared memory be a more efficient underlying mechanism
supporting interprocess bash variable communication than using files?

-- 
Regards,
Peng



reply via email to

[Prev in Thread] Current Thread [Next in Thread]