while read -r; do line=$REPLY ... done < text.txt. To preserve leading and trailing whitespace in the result, set IFS to the null string: while IFS= read -r; ...
wiki.bash-hackers.org