file not found error during loop

Hi,
I have a strange problem and I'm sure its because I'm doing something stupid.
When I loop through all of the files in a directory they cannot be found.

Any help would be greatly appreciated.

Thanks,

-E

$ touch a.txt
$ touch b.txt
$ ls
a.txt b.txt
$ for f in `ls` ; do echo file $f; done
file a.txt
file b.txt
file
$ for f in `ls` ; do file $f; done
a.txt: ERROR: cannot open `a.txt' (No such file or directory)
b.txt: ERROR: cannot open `b.txt' (No such file or directory)
: ERROR: cannot open `' (No such file or directory)
$ file a.txt
a.txt: empty
$

please post the output of ls -lib

Try giving quotes

 for f in `ls`; do file "$f"; done

When you post code, please wrap it in

 tags.

And please do not change the size of the type; you made it too small to be readable. Not to mention adding dozens of tags that had to be removed before I could edit the post.


 
$ touch a.txt
$ touch b.txt
$ ls
a.txt b.txt
$ for f in `ls` ; do echo file $f; done

[/quote]

[indent]
The is not the way to loop through a list of files. Not only is ls unnecessary, but it will break the script if any filenames contain spaces or special characters.

for f in *;  do echo file "$f"; done
for f in * ; do file "$f"; done

Note, however, that you don't need the loop in either case

printf "%s\n" *

file *