Having this odd issue with a simple bash script:
#!/bin/bash
function printLinesFromInput {
COUNTER=1
while read USER; do
echo "Hello $USER";
echo
done < $1
}
while read USER; do
echo "Hello $USER";
done < south-park.txt
echo
echo "In function:"
echo $(printLinesFromInput south-park.txt)
It prints:
$ ./readFile.sh
Hello Eric
Hello Kyle
Hello Stan
Hello Kenny
In function:
Hello Kenny
The function is not echoing all four lines of the file. I am wondering why is this the case. The input file south-park.txt is:
Eric
Kyle
Stan
Kenny
Hello Eric Hello Kyle Hello Stan Hello Kennyas expected (on one line because of$()).