简体   繁体   中英

evaluating lines from stdout

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!

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

This should do what you want:

for string in "a" "b" "c"
do
    output=`echo ${string}`
    echo ${output}
    if [ ${output} == "b" ] ; then
        echo "do something"
    fi
done

Just replace the first echo with your program.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM