[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Check the error status of process substitution
From: |
Masahiro Yamada |
Subject: |
Re: Check the error status of process substitution |
Date: |
Wed, 8 Jun 2022 01:12:13 +0900 |
On Tue, Jun 7, 2022 at 7:17 AM Koichi Murase <myoga.murase@gmail.com> wrote:
>
> 2022年6月7日(火) 3:01 Masahiro Yamada <masahiroy@kernel.org>:
> > Perhaps, one approach is to say
> > "please update your bash", but
> > let me ask if there is a better solution.
>
> I believe that the traditional way is to use a named pipe explicitly,
> though you might be interested in a solution without external commands
> like mktemp/mkfifo.
>
> tmp=$(mktemp -d)
> mkfifo "$tmp/pipe"
> trap 'rm -r "$tmp"' EXIT
>
> nr_lines=0
> (echo a; echo b; echo c; exit 123) > "$tmp/pipe" &
> while read -r _; do
> nr_lines=$(( nr_lines + 1 ))
> done < "$tmp/pipe"
>
> # This checks the exit code of the shell running 'echo a; echo b; echo c'
> wait "$!"
>
> echo "$nr_lines ($?)"
>
> --
> Koichi
Thanks,
I want to run the while-loop in the current shell
instead of a subshell context.
With Kerin's suggestiton, I decided to
use a pipeline + 'lastpipe' option.
--
Best Regards
Masahiro Yamada