I have a .txt file with the following content:
"[email protected]"
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 [email protected] text"
while read line;
do
echo "text $line text"
done <./textfile.txt
But all I get is: text"[email protected]"
--> 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 "[email protected]"
--> After the first text, there is a whitespace but after [email protected], there is no text.
textat each end of yourechostatement you can't tell when you see the stringtextin the output if it's the string from before$lineor 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 thetextafter$linethat's missing, it's thetextbefore it that's missing as it's being overwritten by thetextafter it. Changeecho "text $line text"toecho "foo $line bar"and it'll be much easier for you to see what's really happening.