[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bash process substitution weird behavior
From: |
Greg Wooledge |
Subject: |
Re: bash process substitution weird behavior |
Date: |
Tue, 8 Dec 2015 09:38:30 -0500 |
User-agent: |
Mutt/1.4.2.3i |
On Tue, Dec 08, 2015 at 09:03:08PM +0900, Hyunho Cho wrote:
> # result is in red-colored after external date command output
> # i think there must be no red-colored because { echo 111; date; echo 222 ;}
> only direct to stdout
>
> BASH$ { echo 111; date; echo 222 ;} 2> >( echo -en "\e[01;31m" >&2; read
> line; echo "$line" >&2; echo -en "\e[0m" >&2 )
>
> 111 # white colored
> Tue Dec 8 20:33:33 KST 2015 # red colored
> 222 # red colored
What you have here is a race condition.
You are launching a background process (echo -en ...) which writes to
the shell's stderr, then tries to read from stdin, then writes some
more stuff to the shell's stderr.
While that background job is running, you write various lines to the
shell's stdout.
The order of the arrival of the output of the background job (echo -en)
and the output of the foreground job (echo 111) is not predictable.