Deleting files from all users applciation support folder

TheCRPGroupIT
New Contributor

I'm upgrading custom PDF options in both the root library and user library and need a way to delete the existing files I've come across a script working till it tries to use the user$ variable in the file path. Trying to figure out what I'm doing wrong or if there is a better way to do this. Here is the script:

 

#!/bin/bash

# Get a list of users, filtering out service accounts, root, daemon, and nobody...
#
users=$(dscl . list /Users | grep -v -e '_' -e 'root' -e 'daemon' -e 'nobody')

# Loop through the list of users.
for user in [$users]; do
# Put the path to the directory in a variable.
# The quotes escape the spaces.
#
[ $dir= ]"/Users/$user/Library/Application\ Support/Adobe/Adobe\ PDF/Settings"

# For each $user, delete the directory if it exists.
if [ -d "$dir" ]; then
rm -rf "$dir"
fi
done

 

 

1 REPLY 1

Tribruin
Valued Contributor II

Without running your script a couple of mistakes:

for user in [$users]; do

That is not the correct way to reference an array. Try:

for user in ${users[@]}; do

Also this line is incorrect. 

[ $dir= ]"/Users/$user/Library/Application\ Support/Adobe/Adobe\ PDF/Settings" 

It should be:

dir="/Users/$user/Library/Application Support/Adobe/Adobe PDF/Settings"

You don't need to escape the space if you enclose the spaces in quotes in both the variable assignment and when you use the variable.