Consider the following command:
bash -c "echo x; cat 1" | tee 1.
My understanding is that it would fork to a new shell, write
x to stdout, write
file 1 not found to stderr, exit and return control to the parent process, and write
x to stdout and to
1. Hence, I would expect the final output to be
x, and the file
1 contains exactly the string
However, this is not the case. In actuality, the file
1 usually contains at least two instances of
x, and sometimes thousands of lines of
xs. On a batch test of running the command ten thousand times, the mean number of
xs written to the file was 52.3, and the median was 1. What mechanic is causing this? What probability distribution models this behavior? I suspect that it is conditionally geometric and otherwise uniform.