On Fri, May 23, 2025, 17:17 Stephen Leaf <smileaf@gmail.com> wrote:
>
> #!/bin/bash
> TMPFILE=$(mktemp /tmp/tmp.XXXX)
> for a in this is a test; do
> if [ $a == 'a' ]; then
> >&2 echo b
> fi
> done 2> >(echo "test!"> "$TMPFILE")
>
The process substitution is asynchronous, so the write may not complete by
the time the next command executes.
Try adding "wait $!" here to wait for it to complete.
>
> #touch "$TMPFILE"
> if [ -s "$TMPFILE" ]; then
> echo temp file is not empty
> else
> echo temp file is empty
> fi
> echo "Contents of $TMPFILE"
> cat $TMPFILE
> rm $TMPFILE
>
> I get the output of:
> temp file is empty
> Contents of /tmp/tmp.LGvR
> test!
>
> if I touch or cat the TMPFILE before the test, it behaves as expected.
>