so I'm trying to write a bash script that would look at all the subdirectories in the specified folder and return the maximum number of files in one subdirectory. Here is what I have right now:
#!/bin/bash
maxCount=0
fileCount=0
find ./testdata/ -maxdepth 1 -mindepth 1 -type d | while read dir; do
fileCount= find "$dir" -type f | wc -l
if [ $fileCount -gt $maxCount ]
then
maxCount= "$fileCount"
fi
done
echo "$maxCount"
Firstly, the fileCount variable is not configured properly. Search result for "$ dir" -type f | wc -l is still set to stdout and as such the script continues to return zero.
Example of current output:
1
1
2
1
1
1
0
Where the last zero is the output for the echo "$ maxCount"
Not quite sure what I'm doing wrong. Thank!
Using xfce4 terminal
source
share