Subject: Re: [ast-developers] Non-deterministic ksh behavior
--------
> #!/usr/bin/ksh
>
> while true; do
> /bin/echo "test" > /tmp/file | head
> if [ ! -s /tmp/file ]; then
> echo; exit
> else
> echo -n "."
> fi
> done
>
> While I understand that there is a "mistake" in the script and head(1) will
> never receive any input, I can't explain why /tmp/file is sometimes empty when
> the test is evaluated:
>
>
There is a race condition.
When the redirection happens, the pipe output fd is closed so that
the head will get EOF.
However, at the same time /bin/echo writes test to /tmp/file.
However, if you are running ksh93, then doing
set -o pipefile
before the pipeline will eliminate the race condition since
the parent shell that waits for the pipeline needs to
know the exit status for /bin/echo before the pipeline command
completes.
David Korn
[EMAIL PROTECTED]
_______________________________________________
ast-developers mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-developers