Take the 2-minute tour ×
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

2 Answers 2

up vote 9 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 at 20:35

Your Answer

 
discard

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.