In the below function, I'm trying to print the file name if there are any files in the directory or an error if there's not, but the else part of the inner if/else block, which prints the error message, never runs.
It should be something logical but I can't figure it out.
walk_dir () {
shopt -s nullglob dotglob
for pathname in "$1"/*; do
if [ -d "$pathname" ]; then
printf "\nFiles under $(basename "$pathname")\n";
printf "==========================================\n";
walk_dir "$pathname";
else
fc=$(find "$pathname" -maxdepth 1 -type f | wc -l);
# Here is the problem
if [ $fc -gt 0 ] && [ ! -z $fc ]; then
printf '%s\n' $(basename "$pathname");
else
printf '\e[30mNo candidate file found.\e[39m\n';
fi
fi
done
}