Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bash doesn't have scopes, declare variables with local, imp for recursion #21

Open
sanjarcode opened this issue Nov 1, 2023 · 1 comment
Assignees

Comments

@sanjarcode
Copy link
Member

sanjarcode commented Nov 1, 2023

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
}
@sanjarcode sanjarcode self-assigned this Nov 1, 2023
@sanjarcode
Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant