I need to run some commands in OS X User directories, apart from “Shared” and our local admin account.
So far, I have:
#!/bin/bash
userFolders=$(find /Users/ -type d -depth 1 | sed -e 's/\/\//\//g' | egrep -v "support|Shared")
for PERSON in "$userFolders"; do
mkdir $PERSON/Desktop/flagFolderForLoop
done
Running the above as root, I get
mkdir: /Users/mactest1: File exists
Where might I be going wrong?
You should remove the quotes around
"$userFolders"so that your loop iterates over each person correctly.The following example illustrates the difference between quoting and not quoting:
With quotes:
prints only one parameter:
Without quotes:
prints each parameter:
Also, you can tell
findto exclude certain directories, like this: