This question already has an answer here:
If parsing the output of
ls is dangerous because it can break on some funky characters (spaces,
\n, ... ), what's the best way to know the number of files in a directory?
I usualy rely on
find to avoid this parsing, but similarly,
find mydir | wc -l will break for the same reasons.
I'm working on Solaris right now, but I'm looking for a answer as portable across different unices and different shells as possible.