I am writing a bash script to process output from a mosquitto_sub call:
function testPipe(){
read foo
IFS=' ' read -ra ARRAY <<< "$foo"
topic=${ARRAY[0]}
cmd=${ARRAY[1]}
echo "topic = $topic cmd = $cmd"
cat
}
function pipeTee(){
tee -a mqtt_broker.log
}
mosquitto_sub -h $HOST -p $PORT -t $TOPIC \
-u $USER -P $PASS -v | pipeTee | testPipe
I tried to follow along from Pipe demon output to a function . However, here is what I observe, the first message arrives over the wire and the function testPipe is called and I see the parsed line. All subsequent messages are printed to the console raw, that is as they come in from network.
What might I be doing wrong? Does the "read foo" not consume the input in STDIN?