(unnamed) - display the effective user name, BSD-ish

Jeff Beadles jeff at quark.WV.TEK.COM
Sat Jul 8 14:53:20 AEST 1989


In article <14448 at bfmny0.UUCP> tneff at bfmny0.UUCP (Tom Neff) writes:
>If you need a FAST way to generate the name of your current effective
>user (including the effects of su(1) etc), this works.  It's not fancy.
>Obviously it has to read /etc/passwd.  Feel free to hack and pass
>around.

This isn't fancy, nor as fast I would guess.  However, it's N I C E
to have sources back in alt.sources.  Here's a shell script version of
Tom's program.  I only tested it on a 4.2 based system here, so beware.


#!/bin/sh
#
# This needs a name.  I called it foo23, as foo0-22 was taken :-)
#
# Have fun.  Written by Jeff Beadles  jeff at quark.WV.TEK.COM
# Use at your own risk :-)
#
# If you have id, this will get the username of the person running it.
#
# It's probably not perfect, but it works for me.  If you
# don't like it, see rm(1)  (Or, if you INSIST on using C, unlink(2))
#
# Sed is your friend.

ID=`id | sed 's/^[^0-9][^0-9]*\([0-9][0-9]*\).*$/\1/'`
#echo "ID: $ID"

sed  -n "s/^\([a-z][a-z]*\):.*:$ID:.*:.*:.*:.*$/\1/p" < /etc/passwd | line

# If you don't have line, use "sed -n 1p"


--
Jeff "It's nice to have sources back in alt.sources" Beadles
jeff at quark.WV.TEK.COM



More information about the Alt.sources mailing list