Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8055611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:26:34+00:00 2026-06-05T08:26:34+00:00

I am trying to resolve an issue with a bash script that is intended

  • 0

I am trying to resolve an issue with a bash script that is intended to search through each users home directory in /Users/ and find two different directories, stored in array “SUBDIRS.” If these directories exist, I want to remove with the recursive and force options. If they do not exist I want the script to continue looking for the next directory, next home folder, etc.

#!/bin/sh


err=0




SUBDIRS=(
    "Library/Application Support/Spotify"
    "Library/Caches/com.spotify.client"
)


for HOMEDIR in /Users/*; do

    for SUBDIR in ${SUBDIRS}; do

        DIR="${HOMEDIR}/${SUBDIR}"

            if [[ -d "${DIR}" ]]; then
                rm -rf "${DIR}"
                echo "${HOMEDIR}/${SUBDIR} has been removed."
                APP=$(find "${HOMEDIR}" -name [sS]potify.app)
                rm -rf "${APP}"
            fi

    done

done

exit $err
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T08:26:36+00:00Added an answer on June 5, 2026 at 8:26 am

    You need to signify that it’s an array to be expanded (and quote it).

    for SUBDIR in "${SUBDIRS[@]}"; do
    

    You should quote the pattern in the find command so find will expand it instead of the shell.

    APP=$(find "${HOMEDIR}" -name '[sS]potify.app')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a simple bash script that accepts all arguments and interprets
Im trying to resolve an issue where when using NHibernate with a SqlServerCeDriver that
really struggling to resolve this issue. using nhibernate Im trying to join two different
Hello I've been trying to resolve the issue that I've been having with the
I'm trying to resolve an issue that I brought up at the end of
In trying to resolve the issue I was having for: managing website on windows
I am trying to resolve a design issue implementation in typo3. Essentially I have
I am going nuts here trying to resolve a cascading update/delete issue :-) I
In my efforts to resolve Python issue 1578269 , I've been working on trying
I'm trying to create a patch for cf.vim to resolve an issue with hashes.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.