LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   shell script to print the groups of the users. (https://www.linuxquestions.org/questions/linux-server-73/shell-script-to-print-the-groups-of-the-users-940178/)

erudite 04-17-2012 02:00 AM

shell script to print the groups of the users.
 
xxx

druuna 04-17-2012 02:45 AM

Hi,

This looks like homework, which we will not do for you. We are willing to help though.

What have you tried and what did or did not work?

Hints: Use a loop to read the user names and have a look at the id command.

Hope this helps.

catkin 04-17-2012 02:47 AM

It's your job, intended to train you (not us), so what have you tried so far?

erudite 04-17-2012 03:09 AM

nope..it isnt a homework..i was just trying different possible stuff i can do since i just satrted learning bash shell..What i thought of is having a loop..but how to proceed i dont know..

So plz plz give the algorithm for this..

druuna 04-17-2012 03:16 AM

Hi,

Have a look at this:
Code:

while read NAME; do echo -n "${NAME} : " ; id -nG ${NAME}; done < infile
Or as full script:
Code:

#!/bin/bash

while read NAME
do
  echo -n "${NAME} : "
  id -nG ${NAME}
done < infile

I leave it up to you to figure out how this works, that way you'll actually learn something.

Hope this helps.

erudite 04-17-2012 03:38 AM

xxx

druuna 04-17-2012 03:54 AM

Hi,

If you use a while loop (see post #5) you don't need the export user=`cat groups.sh.....` part.

Hope this helps.


All times are GMT -5. The time now is 05:28 AM.