I have a .txt file with the following content:
"aaa@bbb.de"
Now, I want to paste these strings with the help of my while loop to the stdout, in such a way that echo should write "text aaa@bbb.de text"
while read line;
do
echo "text $line text"
done <./textfile.txt
But all I get is: text"aaa@bbb.de"
--> The whitespaces are missing and the text
after $line
as well.
If I change it as below
while read line;
do
echo "text\ $line text"
done <./textfile.txt
I get text "aaa@bbb.de"
--> After the first text
, there is a whitespace but after aaa@bbb.de
, there is no text
.
text
at each end of yourecho
statement you can't tell when you see the stringtext
in the output if it's the string from before$line
or the same string from after it. Given that, when you sayThe whitespaces are missing and the text after $line as well.
you're misdiagnosing the problem - it's not thetext
after$line
that's missing, it's thetext
before it that's missing as it's being overwritten by thetext
after it. Changeecho "text $line text"
toecho "foo $line bar"
and it'll be much easier for you to see what's really happening. – Ed Morton Jan 13 '22 at 14:18