3 ms·
It's good to be aware of these pitfalls, but in practice they often don't arise. If you're parsing log files, or any other system-generated files with sane file
by ams6110 12y ago
It's good to be aware of these pitfalls, but in practice they often don't arise. If you're parsing log files, or any other system-generated files with sane filenames (no spaces, or other odd characters) you won't have an issue. Still, I normally would never attempt to parse 'ls' for this sort of thing. The preferred approach in a shell script is to use the shell's globbing capabilities (as in the example given):
for f in *; do
[[ -e $f ]] || continue
...
done