Skip to content

Instantly share code, notes, and snippets.

@bwmorales
Last active February 9, 2018 19:15
Show Gist options
  • Save bwmorales/92ffb8ef4e7ae571e72b0840044dc675 to your computer and use it in GitHub Desktop.
Save bwmorales/92ffb8ef4e7ae571e72b0840044dc675 to your computer and use it in GitHub Desktop.
(macOS) Iterate through users, performing some task.
# Iterate through users and perform some tasks.
# Variables and functions that need to be accesible in subshells must be exported (duh).
# Enclose arguments in single-quotes to preserve bash internal variables, etc.
# Example Usage:
# userIteration 'remove "$HOME/Library/Containers/com.microsoft.Excel"'
userIteration() {
for ITERATED_USER in $(dscl . list /Users UniqueID | awk '$2 >= 500 {print $1}'); do
su $ITERATED_USER -c "$*"
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment