2 ms·
The "for f in `ls * `; do" example is actually not useless. It has the quality that the loop will not run if there are no files, because ls produces no output.
by sleepydog 13y ago
The "for f in `ls * `; do" example is actually not useless. It has the quality that the loop will not run if there are no files, because ls produces no output. Compare:
$ for i in `ls * 2>/dev/null`
do
cat $i
done
$
$ for i in *
do
cat $i
done
cat: *: No such file or directory
Imagine that instead of cat we have a large, complex, expensive loop and don't want to pass a useless '*' to it if we can avoid it.