[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: read built-in command has a problem in shell function
From: |
Andreas Schwab |
Subject: |
Re: read built-in command has a problem in shell function |
Date: |
Mon, 11 Oct 2021 09:42:00 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) |
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, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."
Re: read built-in command has a problem in shell function, Greg Wooledge, 2021/10/11