2016-04-13 08:10:15 +0200, Geir Hauge:
[...]
>     while read -r line; do echo "$line"; done < test.txt
> 
> though printf should be preferred over echo:
> 
>     while read -r line; do printf '%s\n' "$line"; done < test.txt
[...]

Actually, you also need to empty $IFS

while IFS= read -r line; do printf '%s\n' "$line"; done < test.txt

And if you want to keep eventual spurious characters after the
last NL character in the file:

while IFS= read -r line; do printf '%s\n' "$line"; done < test.txt
[ -z "$line" ] || printf %s "$line"

For details, see:

https://unix.stackexchange.com/questions/209123/understand-ifs-read-r-line
https://unix.stackexchange.com/questions/65803/why-is-printf-better-than-echo
https://unix.stackexchange.com/questions/169716/why-is-using-a-shell-loop-to-process-text-considered-bad-practice

-- 
Stephane

Reply via email to