The technique I use is overkill. I could have used
dscl . -read /Users/$USER RealName | tail -1
but then I would end up with the name plus a leading white space.
dscl . -read /Users/$USER RealName | tail -1 | sed -e "s/^\ //"
That line fishes the real name out of dscl's database, then eliminates the first line altogether and finally removes the leading white space if there is one.
Here a snippet from my shell:
mac-mini-intel:Tasks kjanson$ res=`dscl . -read /Users/$USER RealName | tail -1`
mac-mini-intel:Tasks kjanson$ echo "'$res'"
' Kai Janson'
mac-mini-intel:Tasks kjanson$ res=`dscl . -read /Users/$USER RealName | tail -1 | sed -e "s/^\ //"`
mac-mini-intel:Tasks kjanson$ echo "'$res'"
'Kai Janson'
--Kai