Reputation: 930
So I am editing my .bashrc file (the one used when I log in) and I want to have it so it outputs "Hello FIRSTNAME LASTNAME (USER)."
I know how to access the user using $USER and get that part. Currently I have the FIRSTNAME and LASTNAME stored in variables but I wondering if there was any way to retrieve my actual first and last name.
I've tried getent passwd USER
but that gives me more than I want.
So, is there a simple way to get the firstname and lastname or will I have to resort to manually entering it in?
Thanks.
Upvotes: 2
Views: 2415
Reputation: 17157
FULLNAME=$(getent passwd $USER | cut -d : -f 5)
By the way, splitting full name into first and last name is a very bad idea, there are many people in this world where their full name doesn't split into those two categories.
Upvotes: 4