View Full Version : Using a shell script to get someones linux username?
Johnsie
December 4th, 2008, 09:30 PM
Hi, I'm trying to write a shell script that copies a file to:
~/.wine/drive_c/windows/profiles/<USERNAME>/Application Data/test
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
sisco311
December 4th, 2008, 09:36 PM
~/.wine/drive_c/windows/profiles/$USER/Application Data/test
you can use the $USER environment variable (https://help.ubuntu.com/community/EnvironmentVariables)
stroyan
December 4th, 2008, 09:37 PM
You can use "$LOGNAME" or "$USER". They are documented in "man login" and "man environ".
DieB
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
Johnsie
December 4th, 2008, 09:40 PM
thanks that great :-)
stefanadelbert
December 4th, 2008, 10:54 PM
You could use
id -nu
Par example
#!/bin/bash
echo "Your home directory is: /home/$(id -nu)"
exit 0
Stef
Powered by vBulletin® Version 4.2.2 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.