This question already has an answer here:
I have been told that it is unwise to parse the output of LS due to security precautions.
The adage used was "parse sparsely and dont eat parsley"
I was attempting to count the amount of files within a directory by using
ls -la | wc -l
I was told to never, never do this but I cant grasp why.
I was told one reason is because a file name could be shuffled into another command by accident. For example, if a file was within the directory named '-l'.
I was also told about using '--', for example ls -la --. If I understand correctly this is supposed to tell bash where to signal the end of commands but even if you used this you still shouldn't parse the output of ls.