Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to obtain home dir of any user with echo

echo ~puchuu
>> /home/puchuu

But I cant use variable

echo ~$USER
>> ~puchuu
echo `echo ~$USER`
>> ~puchuu
share|improve this question

3 Answers 3

up vote 25 down vote accepted

You can use eval:

eval echo ~$USER
share|improve this answer

This might work for you:

homedir=$( getent passwd "$USER" | cut -d: -f6 )
share|improve this answer
Great; I didn't even know about "getent" – David Tonhofer Feb 2 '14 at 20:35

It seems you are that user -- why not

echo $HOME


share|improve this answer
@DavidPostill, I read question AND answers (especially accepted one). Please tell me how you get directory for user other than yourself by running eval echo ~$USER? I am all ears -- last time I checked, $USER evaluates to current user, meaning yourself. – greenoldman Dec 18 '14 at 17:04
@Arjan It appears that the question was not so clear ... :/ – DavidPostill Dec 18 '14 at 21:53
Yeah, that is what i've looking for – deFreitas Apr 27 at 2:13
This won't work if you are in a sudo'ed environment and did not pass sudo the -H or -i flags - $HOME will still be the previous (sudo'ing) user's home directory. – Asfand Yar Qazi Jun 12 at 11:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.