help-bash
[Top][All Lists]
Advanced

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

Re: Check the error status of process substitution


From: Koichi Murase
Subject: Re: Check the error status of process substitution
Date: Tue, 7 Jun 2022 07:17:14 +0900

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



reply via email to

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