Bug in users command

Bill Davidson billd at fps.com
Sat Jan 19 12:36:58 AEST 1991


In article <11104 at jpl-devvax.JPL.NASA.GOV> lwall at jpl-devvax.JPL.NASA.GOV (Larry Wall) writes:
>And here's one in Perl.  (I recognize that hardcoding the template
>for the utmp structure is a weakness.  On the other hand, it's short
>and to the point.  I refer you to the definition of "Minimalism" in
>the Perl book.)

The perl version is probably faster but if for some reason you don't
have perl and you don't mind it being slightly slower:

% cat > users.sh
#!/bin/sh
USERS=`who|sort|awk '{print $1}'`
echo $USERS
^D
% chmod +x users.sh
% users.sh
bambam barney betty dino dino fred pebbles wilma

I'd say that's pretty minimal.  Of course it assumes that your shell
can handle back quotes reasonably and that the user name is the first
field in the output of "who" but nobody's perfect.  If you want to cut
out reports of repeat logins, just add a "-u" parameter to the "sort".

--Bill Davidson



More information about the Comp.bugs.4bsd.ucb-fixes mailing list