7 Jan 2008

continous read from bash pipe

Pipes are great, I love pipes. This is the reason I love the unix way of live, thousands of small utilities (if you know them) which usually read from /dev/stdin and output to /dev/stdout. So simple and powerfull that it is often overseen (by gui users). Tese examples are for bash:

Creating a pipe

mkfifo /tmp/pipe

Continously reading from a pipe:
while true; do
if [[ ! -p /tmp/pipe ]]; then break; fi
l="`cat /tmp/pipe`";
echo "$l";
done &

Writing to the pipe:
echo -en "a\nb\n" >> /tmp/pipe