Skip to main content
Solved

.sh script help - for loop not properly processing variable


Forum|alt.badge.img+2

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 ~ %

 

 

 

Best answer by spotmac

#!/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 original

2 replies

Forum|alt.badge.img+9
  • Contributor
  • 32 replies
  • Answer
  • November 8, 2021
#!/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! 


Forum|alt.badge.img+2
  • Author
  • New Contributor
  • 1 reply
  • November 8, 2021
spotmac wrote:
#!/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.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings