I have an interesting scenario ...
EDIT: I am considering the scenario where there is a large amount of test flowing into stdin (like loop.sh) which is read at a slower rate in some other program (loop2.sh). I make the following assumption: only the latest data is important all previous data can be discarded. I have been considering real time text filtering on stdin, are there any solutions? This is was my experiment to test it the stdin buffer:
This is loop.sh
#! /bin/bash
i=0
for (( ; ; ))
do
echo "$i" >&2
echo "$i"
((i++))
done
And this is loop2.sh
#! /bin/bash
i=0
for (( ; ; ))
do
echo "Count: $i"
((i++))
sleep 1
done
i run the following: ./loop.sh | ./loop2.sh
and i get:
...
12762
12763
12764
12765
12766
12767
12768
12769
Count: 2
Count: 3
Count: 4
Count: 5
Count: 6
Count: 7
Count: 8
Count: 9
...
Essentially the stdin buffer from loop.sh has filled up :D
And that halted execution too!!!
My question is can i change this behaviour? ie) automatically overwrite stdin or change the size? additionally why 12769? how big is the default?