Using :execute
was correct idea, but you also need to use system()
function to get the output of an external command:
command! gohome :execute 'cd' system('echo $HOME')
For paths that have spaces this should be better:
command! gohome :execute "cd '".system('echo $HOME')."'"