Get home directory by username
You can use eval
:
eval echo ~$USER
But see Andrew's comment and glenn's reply below.
This might work for you:
homedir=$( getent passwd "$USER" | cut -d: -f6 )
This will also work on users that are not you. For instance,
homedir=$( getent passwd "someotheruser" | cut -d: -f6 )
It seems you are that user -- why not
echo $HOME
?