I'm attempting to read all the lines of a file and concatenate them into a string. After Googling extensively, here's what I have:
#!/bin/bash
filename='file.txt'
files=''
while read p; do
files="$files $p"
done < $filename
echo $files
The problem is that it seems the files variable seems to get overwritten each time. Shouldn't it just be appending it?
Example file.txt:
test1
test2
test3
Output is:
test2
(Note that I intentially posted this as is - there is a space prior to the word test2 in the output)
test1 test2 test3files=$(cat $filename).