Read a file using a bash script
cat file | while read line
do
echo "a line: $line"
done
EDIT:
To get file contents into a var use:
foo="`cat file`"
There's no reason to use cat
here -- it adds no functionality and spawns an unnecessary process.
while IFS= read -r line; do
echo "a line: $line"
done < file
To read the contents of a file into a variable, use
foo=$(<file)
(note that this trims trailing newlines).