Spaces are delimeters in a BASH array. You are creating the array adminUsers and then looping through it. if you were to echo $adminUsers you see something like:
root user1 The Admin secondAdmin
To BASH that is 5 different array elements.
The big question is how do have a username with a space in it? That should not be possible. Are you sure "The Admin" is a username and not a Real Name?
Also, your cut command in the 2nd line is incorrect. It should cut -c 18- . Otherwise you are getting the first 18 characters.
Spaces are delimeters in a BASH array. You are creating the array adminUsers and then looping through it. if you were to echo $adminUsers you see something like:
root user1 The Admin secondAdmin
To BASH that is 5 different array elements.
The big question is how do have a username with a space in it? That should not be possible. Are you sure "The Admin" is a username and not a Real Name?
Also, your cut command in the 2nd line is incorrect. It should cut -c 18- . Otherwise you are getting the first 18 characters.
Hello, Thanks for the response!
After doing some digging, a previous person that used to work on Jamf, created this setting in PreStage enrollment where it created a local admin account with spaces in it. And I guess by creating it this way, the username was able to have space in it?
My worry was that other devices may have different usernames with spaces in it. So if I need to remove admin privilege from it, it wouldn't work. But from what it sounds like, there should be no other accounts with spaces in them, unless it was done by how I mention above.
I thought the - after the 18 means it cut the characters after the 18th character? When I tried the script with the dash after the 18, and I did an echo of the results, it returned with nothing
Could you use the user ID instead? Not that I know if dseditgroup takes GIDs for operations.
Ignoring the space existing in a username issue the scripting part could be done this way
# by replacing [ with [[ you're able to wildcard the comparison.
# instead of seeing if the username = "The Admin" see if it = *"Admin"*
if [[ "$user" != "root" ]] && [[ "$user" != *"Admin"* ]] && [[ "$user" != "secondAdmin" ]] ; then