I am practising to use the command read
:
$ ls * | while read line; do printf "test %s\n" $line; done
test data1.txt
test data5.txt
test data6.txt
test data7.txt
It works properly, but
$ ls * | while read line; do file $line; done
data1.txt: cannot open `data1.txt' (No such file or directory)
data5.txt: cannot open `data5.txt' (No such file or directory)
data6.txt: cannot open `data6.txt' (No such file or directory)
data7.txt: cannot open `data7.txt' (No such file or directory)
data8.txt: cannot open `data8.txt' (No such file or directory)
The file names are legal
$ ls
data1.txt data5.txt data6.txt data7.txt data8.txt
What's the problem with my code.