I’m trying write simple notify app in bash. I want to read output from mplayer, parse it and display through notify-send.
I can get desired info from mplayer using this:
mplayer <url> | grep ICY
and then parse in using sed.
I create named pipe, tell mplayer to write it and then I’m reading from it. Unfortunately, it doesn’t work. Here’s my script:
$fifo=~/.rp/fifo
mkfifo $fifo
mplayer <url> 2>/dev/null | grep ICY 1> $fifo &
while read line < $fifo; do
echo $line
done
wait
Program keeps waiting to input from $fifo. I tried following in other terminal, while this script is running:
-
Run
echo "Test" > .rp/fifoTerminal with running script shows “Test”
-
Run
echo "ICY" | grep ICY > .rp/fifoalso works.
-
Run
mplayer <url> | grep ICY > .rp/fifoand it doesn’t work.
Is I said above, the combination of mplayer | grep works fine. grep > $fifo works fine. I don’t understand why mplayer | grep > $fifo doesn’t work.
You could do unbuffered grep with:
or better:
or even, why not (sed is very nice for grep and formatting),
this will grep
ICYlines and even split line containing-in a first field of 30 chars length separed by a:from a second field:could give something like: