a sync in hope it syncs pipes makes the date | f work, but not for <( date )
f() { sync; read -t 0 ; printf $?\\n ; } ; date | f ; f <( date ) ; read -t 0 <( date ) ; printf $?\\n 0 1 1 On Mon, Oct 11, 2021, 09:42 Andreas Schwab <sch...@linux-m68k.org> wrote: > On Okt 11 2021, Hyunho Cho wrote: > > > this command works well in *shell script file* > > but in shell function does not work well > > This has nothing to do with shell functions. It is a simple race > condition. > > > sh$ echo 111 | myfunc # OK > > yes > > > > sh$ cat foo.c | myfunc # NOT WORK! > > > > sh$ date | myfunc # NOT WORK! > > > > > > #### if i change like this. then this time work well > > > > sh$ date | { date > /dev/null; myfunc ;} > > yes > > This depends on the left side of the pipe producing output faster than > the right side performing read -t 0. > > Andreas. > > -- > Andreas Schwab, sch...@linux-m68k.org > GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 > "And now for something completely different." > >