Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!zephyr!tektronix!orca!quark!jeff From: jeff@quark.WV.TEK.COM (Jeff Beadles) Newsgroups: alt.sources Subject: (unnamed) - display the effective user name, BSD-ish Message-ID: <3810@orca.WV.TEK.COM> Date: 8 Jul 89 04:53:20 GMT References: <14448@bfmny0.UUCP> Sender: nobody@orca.WV.TEK.COM Reply-To: jeff@quark.WV.TEK.COM (Jeff Beadles) Organization: VERY little... Lines: 36 In article <14448@bfmny0.UUCP> tneff@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@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@quark.WV.TEK.COM