Get your name from the Unix passwd(5) database
I learned this tip from Mike Burns.
Drop into an interactive Ruby shell:
$ irb
Require the Etc
module:
> require 'etc'
From the docs:
The
Etc
module provides a more reliable way to access information about the logged in user than environment variables such as+$USER+
.
Get your name from the GECOS field in the passwd(5)
database:
> Etc.getpwuid.gecos.split(',').first
=> "Dan Croak"
Written by Dan Croak
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#