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, [email protected]
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."