Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

evaluating lines from stdout

Tags:

bash

scripting

I have a bash script that is executing a program in a loop. I want to evaluate each line from the stdout and do something if it matches my condition.

I still want to be able to see stdout on the screen. Is there a simple way to accomplish this? Thanks!

like image 475
j.lee Avatar asked Apr 25 '11 21:04

j.lee


1 Answers

There are several variants of looping over input, but one possibility is thus:

my_cmd | while read line; do
    echo "$line"
    my_process "$line"
done
like image 115
Oliver Charlesworth Avatar answered Sep 20 '22 16:09

Oliver Charlesworth