When I use \"cat test.file\", it will show
1
2
3
4
When I use the Bash file,
cat test.file |
while read data
do
e
Maybe IFS is the key point as others said. You need to add only IFS= between while and read.
cat test.file |
while IFS= read data
do echo "$data"
done
and do not forget quotations of $data, else echo will trim the spaces.
But as Joshua Davies mentioned, you would prefer to use the predefined variable $REPLY.