I am dealing with paths that will have spaces.
I am globbing this way (the second line sets up the glob):
IFS=$'\n'
VAR="$1/"name_*
for file in $VAR; do
echo $file
grep ITEM "$file" | wc -l
done
I need to look only in files that are named name_* under $1. The IFS I set here lets me look at the files properly, because it prevents the for from becoming tripped up by spaces in filenames.
However, I now want an easy way to grab the total number of such files matched by the glob. I know I can use a counter in the for loop, but I was hoping I could use a pipe with my VAR to do this.
However, if I echo $VAR, the globbing occurs successfully, but the different paths are joined by space, which ruins me because I can now no longer separate the items... Is there a way to override this behavior similar to how IFS works on for?
grepor whatnot) the output oflsor whatnot, rather than to glob the path. – Steven Lu Oct 02 '18 at 02:41