[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] How to catch errors in "readarray ... < <(...)"
From: |
Greg Wooledge |
Subject: |
Re: [Help-bash] How to catch errors in "readarray ... < <(...)" |
Date: |
Thu, 26 Mar 2015 12:02:20 -0400 |
User-agent: |
Mutt/1.4.2.3i |
On Thu, Mar 26, 2015 at 10:55:47AM -0500, Peng Yu wrote:
> The error in <() is not cached in the following code. Is there a
> solution to this problem? Thanks.
>
> readarray -t array < <(printf '%s\n' 'a b' 'c d'; exit 1)
> printf "%s\n" "address@hidden"
You can use a named pipe.
pipe=/var/tmp/foop.$$
trap 'rm -f "$pipe"' EXIT
mkfifo "$pipe"
{ printf ...; exit 1; } > "$pipe" & pid=$!
readarray -t array < "$pipe"
if ! wait $pid; then
echo "an error occurred" >&2
fi