help-bash
[Top][All Lists]
Advanced

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

Re: reading from external command


From: Jesse Hathaway
Subject: Re: reading from external command
Date: Tue, 29 Mar 2022 14:02:53 -0500

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.



reply via email to

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