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

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 35 down vote accepted

You can use eval:

eval echo ~$USER
share|improve this answer
In bash eval isn't needed it with just echo ~$username it's okay, but in sh eval is needed if is a variable – Felipe Alcacibar Nov 25 '15 at 14:23
This sometimes gives the wrong value, maybe the home folder of a previous account with the same username? – Andrew MacFie Dec 12 '15 at 18:28
@AndrewMacFie: What do you mean by "previous"? – choroba Dec 12 '15 at 18:49
@choroba Add a user, delete the user, then add a user with the same username. If the user's home folder is different the second time, this command gives the original home folder rather than the current one. glenn jackman's answer gives the current one. – Andrew MacFie Dec 12 '15 at 18:59

This might work for you:

homedir=$( getent passwd "$USER" | cut -d: -f6 )
share|improve this answer

It seems you are that user -- why not

echo $HOME


share|improve this answer
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 '15 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.