2

I am trying to remove the below file for all user accounts through a bash script but the wildcard * does not seem to work. I have been testing the script locally by running it on mac os x terminal.

Plist file to be deleted: com.apple.eap.bindings.XXXXXXX.plist

#!/bin/bash

for dir in /Users/*;
do
    if [[ -e "${dir}/Library/Preferences/com.apple.eap.bindings.*" ]]; then
        rm "${dir}/Library/Preferences/com.apple.eap.bindings.*"
    fi
done

Above code does not delete the file in question but it does work if I point to the exact file name without the wildcard. I have tried removing quotes as well but still does not delete the file. Could someone help please?

2
if [[ -e "${dir}/Library/Preferences/com.apple.eap.bindings.*" ]]; then

In this line you put the asterisk within double quotes. That makes it a literal char and not something which magically expands to filename(s).

Links: double-quotes-vs-asterisk-filename-expansion-in-bash as well as the post already pointed to by Shaun.

You will have to use the asterisk unquoted. Either as in the first part of your script or as an argument to find.

  • 1
    Removing the quotes will fail if the asterisk matches more than one file. Better to use if [ -z "$(echo ${dir}/Library/Preferences/com.apple.eap.bindings.*|grep -q '*')" ]; then – AFH Oct 28 '14 at 21:17
  • Thank you Thank you AFH! That works perfecto! This thing was starting to eat my brains out. Now thats what I call a perfectly helpful & understanding forum answer :) – mgrev Oct 28 '14 at 21:27
2

You could consider this as an alternative

#!/bin/bash
/usr/bin/find /Users/*/Library/Preferences -name "com.apple.eap.bindings.*.plist" -exec /bin/rm -fv "{}" \;

This will effectively remove the files in question. Remove the 'v' switch if you don't want output.

1

If this should help anyone out there, this is what works for me:

#!/bin/bash

for dir in /Users/*;
do
    if [ -z "$(echo ${dir}/Library/Preferences/com.apple.eap.bindings.*|grep -q '*')" ]; then
        rm ${dir}/Library/Preferences/com.apple.eap.bindings.*
    fi
done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.