Introduction
I was trying to do some instructions on a file line by line with:
while IFS= read -r line; do
...
done < file
When I noticed that there was a problem with trailing whitespaces (for example: " a "
=> "a"
) that were automatically deleted, which is a real problem for me.
I searched in the documentation and didn't find any mention of that. And there is the same problem with printf.
Minimal example:
touch example # Create a file
echo " exa mple " >> example # Add some text
cat example # exa mple
echo $(cat example) # exa mple
rm example # Delete the file
In this example, I don't understand why echo $(cat example)
doesn't have some trailing whitespaces.
And this "problem" is also here with:
while IFS= read -r line; do
echo $line # exa mple
done < example
Version:
Tested with:
zsh v5.9
bash v5.2.2