我想从/proc 文件中读取一个特定值,目前这是在"读取行"循环中完成的,作为 scheleton:
while read line
do
if [[ $line = *MATCHES STRING* ]]; then
for (( i=0 ; i<=$someVAR-1; i++ ))
do
[if statement to check if the specific line is not equal with 0]
then [whatever]
done
fi
done < "/proc/FILE"
有了这个,我想进一步改进循环,以便我可以计算 for 循环中的 if 语句返回大于 0 的值的次数。所以停止条件应该是这样的:
if line matches string then
for loop
do
use a variable to keep count that the conditions has been met 2 times.
发生这种情况时,循环应停止并显示一条消息。
while read line
do
if [[ $line = *MATCHES STRING* ]]; then
count=0
for (( i=0 ; i<=$someVAR-1; i++ ))
do
[if statement to check if the specific line is not equal with 0]
then count=$((count+1))
fi
done
if [[ $count -ge 2 ]]
then break
fi
fi
done < "/proc/FILE"