bash concatenate string in loop results in empty string

Solution 1:

Using the pipe essentially creates a new script with a new scope. You can avoid the pipe like so:

#! /usr/bin/bash
myFile=/home/FalcoGer/testfile.txt

result=""
while read -r line
do
  result+="$line "
done < $myFile

echo Result: $result