Hi!
It looks like you're off to a good start! Since it's homework, I won't make any suggestions about doing it a different way, but I can point out some things that I can definitely see that might trip you up in the troubleshooting process!
First: when you want to execute a command and do something with the output, don't use [square brackets], just use the $(commands go here) style. Square brackets [] indicate that you want to do some kind of evaluation (true/false) of the output.
Second: you go to the trouble of setting the "$g" variable, but then you call "$@" again a few lines down, when I assume you just want to work with one value of $@ per loop. Try using "$g" in your evaluation of "if $groupname=$g".
Third: This is the real clue to what's happening, I think! You're working with cut, which is giving you whole columns of data, but you really only need one row out of that column of data for each iteration of "$g". Try using 'awk' or 'grep' to narrow down the results ;)
Once you've tweaked those three things, I think you'll be much closer to a working script. I'm not sure about the logic in the loop where you're calculating $count, but I think when you resolve the three things above, the rest should be easier to sort out.
One more hint... all those numbers *might* be getting printed to stderr instead of stdout... try redirecting stderr to /dev/null, and it could help you see what's actually working a little more clearly! example: [/icode]./script.sh group1 group2 group3 2>/dev/null[/icode]
I hope this helps!
P.S. - try running your script with "bash -x" for debugging output!