Is there a way to get the integer that wc returns in bash?
Basically I want to write the line numbers and word counts to the screen after the file name.
output: filename linecount wordcount
Here is what I have so far:
files=\`ls`
for f in $files;
do
if [ ! -d $f ] #only print out information about files !directories
then
# some way of getting the wc integers into shell variables and then printing them
echo "$f $lines $words"
fi
done
ls
– Goggleeyedfor f in *; do
and skip$files
entirely. If you want to store a list of filenames, the correct data structure is an array:files=( * ); for f in "${files[@]}"; do if [ ! -d "$f" ]; then ...
-- note the quotes, they're important; if you run your code through shellcheck.net and follow the links in the warnings it throws, they go to wiki pages explaining why. – Goggleeyed