I had thought that I had saved an earlier response yesterday. Anyway, whenever you run a program, the running code has associated with it a UID and an EUID ( effective user id ). Certain services that run in the background are started by root, but very quickly will degrade their permissions to that of a system user setup for that purpose. This if for security reasons. Often the service will run in a chrooted jail, which means that the root is changed to a directory with it's own system file hierarchy, but stripped to the bone. Only what is needed to run the service is present, and a shell option reduces the commands that can be used. Even 'cd' doesn't work. That way if a hacker can cause the service to crash, there is another obsticle to overcome, breaking out of the jail.
I was reading parts of the bash manual on arrays and one example read both the uid and uname from /etc/password. I changed it a little here, I thought it might be useful for you.
user_id= ( $( cut -f 1,3 -d: /etc/passwd ) )
Now the variable user_id contains an array of "uname:uid" strings.
You can handle one of them like this:
echo ${user_id[1]}
You can list the entire array like this:
echo ${user_id[@]}
Suppose you want to know how many elements are in user_id. No problem: echo ${#user_id[@]}
So it would be easy to iterate through each element knowing the number of elements.
Code:
NORMALUSERSTART=500
numentries=${#user_id[@]}
for (( index=0; index<numentries; index++ )); do
if (( ${user_id[index]#*:} >= $NORMALUSERSTART )) ; then echo ${user_id[index]%*:}
fi
done
This still will list the nobody user, so you may want to extend the test if that isn't acceptable, or decrement $numentries before the loop.