View Full Version : Using a shell script to get someones linux username?
December 4th, 2008, 09:30 PM
Hi, I'm trying to write a shell script that copies a file to:
I can use ~ to get to the users home dir no problem, but I need to find out their username so that I know which subfolder to place the file into.
Thanks if anyone can help
December 4th, 2008, 09:36 PM
you can use the $USER environment variable (https://help.ubuntu.com/community/EnvironmentVariables)
December 4th, 2008, 09:37 PM
You can use "$LOGNAME" or "$USER". They are documented in "man login" and "man environ".
December 4th, 2008, 09:38 PM
take the printout of whoami put it in a variable and use that instead of USERNAME, above mentioned ways would work better
December 4th, 2008, 09:40 PM
thanks that great :-)
December 4th, 2008, 10:54 PM
You could use
echo "Your home directory is: /home/$(id -nu)"
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.