Bash while read loop extremely slow compared to cat, why?

后端 未结 4 1134
野的像风
野的像风 2020-12-01 19:17

A simple test script here:

while read LINE; do
        LINECOUNT=$(($LINECOUNT+1))
        if [[ $(($LINECOUNT % 1000)) -eq 0 ]]; then echo $LINECOUNT; fi
do         


        
4条回答
  •  难免孤独
    2020-12-01 19:35

    Not really sure what your script is supposed to do. So this might not be an answer to your question but more of a generic tip.

    Don't cat your file and pipe it to your script, instead when reading from a file with a bash script do it like this:

    while read line    
    do    
        echo $line
    done 

提交回复
热议问题