How to read entire line from bash How to read entire line from bash shell shell

How to read entire line from bash


while read -r line; do echo "$line"; done < file.txt


As @Zac noted in the comments, the simplest solution to the question you post is simply cat file.txt so i must assume there is something more interesting going on so i have put the two options that solve the question as asked as well:

There are two things you can do here, either you can set IFS (Internal Field Separator) to a newline and use existing code, or you can use the read or line command in a while loop

IFS=""

or

(while read line ; do    //do something done) < file.txt


I believe the question was how to read in an entire line at a time. The simple script below will do this. If you don't specify a variable name for "read" it will stuff the entire line into the variable $REPLY.

cat file.txt|while read; do echo $REPLY; done

Dave..