Issue
I need to read a file using a "Do/While" loop.
How can I read the contents as a string?
Here's my code:
cat directory/scripts/tv2dbarray.txt | while read line
do
echo "a line: $line"
done
Error:
test.sh: line 4: syntax error near unexpected token `done'
test.sh: line 4: `done'
Solution
cat file | while read line
do
echo "a line: $line"
done
EDIT:
To get file contents into a var use:
foo="`cat file`"
Answered By - Erik Answer Checked By - David Marino (WPSolving Volunteer)