I am trying to learn bash and I did a one liner like such:
for f in *; do echo $f; done
This prints the all the file name in current directory.
Output:
a file
testfile
Since f is able to grab "a file" just fine, then I would do something like this:
for f in *; do
if [ -f ${f} ]; then
LINE=$(wc -l < $f)
WORD=$(wc -c < $f)
echo $f ${LINE} ${WORD}
fi
done
This script failed at line 4 because "a file" has space in them.
What I need help with: Why does it fail?
F is able to grab the filename properley. Intuitively, i would believe that -f ${f}
would be able to check if "a file"
is a file.
Why does that "a file" passed the for loop but failed at the if statement check?