text: Q:
  
  else part of an if/else block never runs in Bash script
  
  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
  }
  
  A:
  
  There are 3 cases for walk_dir
  
  Non-empty folder
  Empty folder
  Regular file
  Ignoring special file, probably N/A here.
  
  When called for non-empty folder, walk_dir will make (recursive) on any sub folder (line #7), and then will print the base name of every regular file in line #12.
  When called with empty folder, walk_dir will do nothing since "$1"/* expand to empty list.
  When the directory contain files, the code will "count" the number of files in line #9. This l only process non-directories - probably files (assuming not special devices, etc). In this case it will make recursive call for each entry in the folder.
  If there are regular files in the folder, the code will execute the find on line #8. On a regular file will always set fc="1", therefore the condition on line 11 will always be true, never getting into the else part on line #13.
       1  walk_dir () {
       2      shopt -s nullglob dotglob
  
       3      for pathname in "$1"/*; do
       4          if [ -d "$pathname" ]; then 
       5            printf "\nFiles under $(basename "$pathname")\n";
       6            printf "==========================================\n";
  
       7            walk_dir "$pathname";
       8          else 
       9            fc=$(find "$pathname" -maxdepth 1 -type f | wc -l);
  
      10            # Here is the problem
      11            if [ $fc -gt 0 ] && [ ! -z $fc ]; then 
      12              printf '%s\n' $(basename "$pathname");
      13            else 
      14              printf '\e[30mNo candidate file found.\e[39m\n';
      15            fi
      16          fi
      17      done
      18   }
  
  