bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: read built-in command has a problem in shell function


From: Alex fxmbsw7 Ratchev
Subject: Re: read built-in command has a problem in shell function
Date: Mon, 11 Oct 2021 09:57:52 +0200

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 <schwab@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, schwab@linux-m68k.org
> GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
> "And now for something completely different."
>
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]