Last active
February 9, 2018 19:15
-
-
Save bwmorales/92ffb8ef4e7ae571e72b0840044dc675 to your computer and use it in GitHub Desktop.
(macOS) Iterate through users, performing some task.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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