2 ms·
It clearly depends on what good that subshell running ls does for you, but the trivial form would be: for i in *txt do ... done The reason to stuff
by xorcist 8y ago
It clearly depends on what good that subshell running ls does for you, but the trivial form would be:
for i in *txt
do
...
done
The reason to stuff every file name through ls (keep in mind that it's always your shell doing glob expansions, ls is not involved) would be to sort them by creation date or some other processing that ls can do. But as soon as there are many files involved, or those sorting arguments gets non-trivial, it will fall apart completely.
Use find | while read instead, or xargs. That's going to be easier on the eyes and actually work.