[英]evaluating lines from stdout
I have a bash script that is executing a program in a loop.我有一个 bash 脚本,它在循环中执行程序。 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.只需用您的程序替换第一个 echo。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.