Shell reads file line by line

1. Parameters can be used externally: variables in the loop can be used outside the loop

 

while read line
do
    echo $line
done < $filepath

 

 

 

2. The parameters in the loop body cannot be used externally: the variables in the loop cannot be accessed outside the loop

 

cat $filepath| while read line
do
echo $line
done

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326414615&siteId=291194637