Concatenating two string variables in bash appending newline

bash, linux, shell

Solution

New lines are very much there in the variable `"$final_list"`. `echo` it like this with double quotes:

echo "$final_list"
url1
url2
url3

OR better use `printf`:

printf "%s\n" "$final_list"
url1
url2
url3

Problem

I have a variable `final_list` which is appended by a variable `url` in a loop as: ``` while read url; do final_list="$final_list"$'\n'"$url" done < file.txt ``` To my surprise the `\n` is appended as an space, so the result is: ``` url1 url2 url3 ``` while I wanted: ``` url1 url2 url3 ``` What is wrong?

Original source