holocene
May 27th, 2010, 04:39 AM
how do I get a list of all users in /etc/passwd into a variable that I can iterate through. Reason: I want to do something based on the value of each user.
For example, if my list of users was $userlist, then I want to do something like this:
for myuser in $userlist
do
some work here on $myuser
done
I know I can use cut like this
cat /etc/passwd | cut -f1 -d:
which gives me one user per line.
but how do I get it into a variable?
for instance, this does not work
userlist=(cat /etc/passwd | cut -f1 -d:)
Thanks in advance. Sorry if this is not the right forum.
Steve.
For example, if my list of users was $userlist, then I want to do something like this:
for myuser in $userlist
do
some work here on $myuser
done
I know I can use cut like this
cat /etc/passwd | cut -f1 -d:
which gives me one user per line.
but how do I get it into a variable?
for instance, this does not work
userlist=(cat /etc/passwd | cut -f1 -d:)
Thanks in advance. Sorry if this is not the right forum.
Steve.