Ubuntu Forums Archive Viewer

Using a shell script to get someones linux username?

Archived thread 1002017 from Programming Talk. Markdown source: Programming_Talk/thread_1002017_Using_a_shell_script_to_get_someones_linux_usernam.md

Original URL About this archive
#1

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

#2

~/.wine/drive_c/windows/profiles/$USER/Application Data/test

you can use the $USER environment variable

#3

You can use "$LOGNAME" or "$USER". They are documented in "man login" and "man environ".

#4

take the printout of whoami put it in a variable and use that instead of USERNAME, above mentioned ways would work better

#5

thanks that great :-)

#6

You could use


id -nu

Par example


#!/bin/bash

echo "Your home directory is: /home/$(id -nu)"

exit 0

Stef