Excerpts from Robin Houston's message of Thu Nov 29 13:19:21 -0500 2007:
perl -le 'print +(getpwuid $<)[6]'
is portable and concise (and not likely to break when Apple change their bizarre tool in yet another incompatible way).
There's also the slightly longer but slightly clearer Ruby equivalent:
ruby -retc -e 'puts Etc.getpwuid.gecos'