views:

28

answers:

4

I'm trying to do something like this:

Say there are 4 users logged into a UNIX machine, a, b, c, and d.

Now, to get the groups these guys belong to, I have to type out :

groups a b c d.

What I am wondering, is if there is a way to do something like who | groups where I can pipe the users currently logged-in to the groups command, which would then print out all the users given along with their group information. However, this does not seem to work as intended - rather, the above command just gives the group the first user belongs to.

+2  A: 

In bash, zsh, and others:

groups $(who | cut -d' ' -f 1)
Ignacio Vazquez-Abrams
+1  A: 

Though I have not checked this one:

who -q | xargs -o groups

But you should be able to use xargs for this

pyfunc
I love xargs! The best part of this solution (compared to backticks or a $() command) is that it allows the logical flow of the command to remain left-to-right
shmuelp
A: 
groups $(who -q)|head -n -1
ghostdog74
A: 
who | while read -r user line; do echo "$user $line" -- `groups $user`; done

This will output the "who" command with the groups on the side

Nicolas Viennot