.sh script help - for loop not properly processing variable

jakebob
New Contributor

I'm working on a script that can run to secure screen screen saver corners. The through is I pull the usernames of non system accounts and put the commands below through a forloop.

Below is my for loop with variable. I added an echo in my troubleshooting. It looks like my for loop isn’t breaking apart each users in the variable’s array.

Anyone run into this or know what I am missing here?

=====================

adminuser@test-mac ~ % userList=$(dscl /Local/Default -list /Users uid | awk '$2 >= 100 && $0 !~ /^_/ { print $1 }')

for u in $userList

do

Echo $user

sudo -u $u defaults write com.apple.dock wvous-tl-corner -int 0

sudo -u $u defaults write com.apple.dock wvous-bl-corner -int 0

sudo -u $u defaults write com.apple.dock wvous-tr-corner -int 0

sudo -u $u defaults write com.apple.dock wvous-br-corner -int 0

done

john.doe

adminuser

sudo: unknown user: john.doe

adminuser

sudo: error initializing audit plugin sudoers_audit

sudo: unknown user: john.doe

adminuser

sudo: error initializing audit plugin sudoers_audit

sudo: unknown user: john.doe

adminuser

sudo: error initializing audit plugin sudoers_audit

sudo: unknown user: john.doe

adminuser

sudo: error initializing audit plugin sudoers_audit

adminuser@test-mac ~ %

 

 

 

1 ACCEPTED SOLUTION

spotmac
New Contributor III
#!/bin/zsh


for dscl_user in $(dscl /Local/Default -list /Users uid | awk '$2 >= 100 && $0 !~ /^_/ { print $1 }')
do
echo ${dscl_user}

done

You have to run the script also with sudo otherwise it will not work! 

View solution in original post

2 REPLIES 2

spotmac
New Contributor III
#!/bin/zsh


for dscl_user in $(dscl /Local/Default -list /Users uid | awk '$2 >= 100 && $0 !~ /^_/ { print $1 }')
do
echo ${dscl_user}

done

You have to run the script also with sudo otherwise it will not work! 

Thanks! This did the trick.