I could grep through /etc/passwd but that seems onerous. 'finger' isn't installed and I'd like to avoid that dependency. This is for a program so it would be nice if there was some command that let you just access user info.
相关问题
- How to get the return code of a shell script in lu
- Is shmid returned by shmget() unique across proces
- NOT DISTINCT query in mySQL
- how to get running process information in java?
- Flush single app django 1.9
Take 1:
However, passwd database supports special character '&' in the gecos, which should replaced with capitalized value of user name:
Most of answers here (except for finger solution) do not respect &. If you want to support this case, then you'll need a more complicated script.
Take 2:
My code works in bash and ksh, but not dash or old Bourne shell. It reads the other fields too, in case you might want them.
You could also scan the whole /etc/passwd file. This works in plain Bourne shell, in 1 process, but not so much with LDAP or what.
On the other hand, using tools is good. And C is good too.
The good old finger may also help :-)
Combination of other answers, tested on minimal Debian/Ubuntu installations: