cleanEmptyFolders() {
local _location="$1"
local _hidden="${2}"
local dir # if this is missed, all variables are shared across activation records (stack frames)
for dir in $(childDirs "$_location"); do
if [[ ! $_hidden && $(basename "$dir") == .* ]]; then
continue # Ignoring hidden folders
fi
echo "Dir: $dir"
echo "Exploring: $dir"
cleanEmptyFolders "$dir" "$_hidden"
if [[ ! $(ls -A "$dir") ]]; then
echo "After check dir: $dir"
rmdir "$dir"
# echo "Empty folder '$dir' deleted."
fi
done
}
I am thinking of switching to a sane lang for scripting - like Python (classic scripting) or JS (I'm fluent). But bash quirks would remain, even if not very relevant.