So I have a list of usernames such as:
user1
user2
user3
I want to apply id
on each of them and get something like:
uid=100(user1) gid=5(g1) groups=5(g1),6(g6),7(g10)
.
.
How can I achieve this? Please note that the list is the output of another command say mycommand
.
Use
xargs
:Example:
You can also loop over the input in bash:
xargs
converts input to arguments of a command. The-L1
option tellsxargs
to use each line as a sole argument to an invocation of the command.With bash, you can capture the lines of output into an array:
And then iterate over them
This is not as concise as xargs, but if you need the lines for more than one thing, it's pretty useful.
First I tested the
find/egrep
to make sure I get the list I want, then I added it as a file list at the end of thetar
command.Hope this helps somewhat.
find .
just finds ALL the files under the current directory, though you could specify a subdirectory or a completely different path if you wish.egrep
just allows for multiplegrep
search strings separated by a pipe (|
).