Help with capturing homedir via ssh and saving to variable

I need to capture the homedir using the ssh command and then saving it to a variable.

The results from the following command is what I need to capture to a variable:
NOTE: the value I'm getting back is also incorrect. as it seems to be getting the home dir from the local server and not the one I'm sshed too!

ssh -o BatchMode=yes $userid@server ~$userid

I've tried redirect but get "ambiguous redirect" error
I've tried just saving it to a variable but it doesn't recognize the command
I've tried piping it to "read HOMEDIR", but that doesn't work.

Any ideas?? :confused:

That ssh command would determine the users homedir on the local server you ran that from and then try to run it on the remote server.

If you just want to ask a remote server what a user's home dir is, and have remote finger enabled, just run finger $userid@$server

If you don't have rfinger available, try:
Redirecting to a file:

ssh $userid@$server "echo ~$userid" > file.txt

Using a variable:

variablename=`ssh $userid@$server "echo ~$userid"`

I tried the finger command, but apparently it failed. It was looking for a socket connection. I'm sure it's been restricted. :eek:

Assigning to a variable worked once I figured out to use the tick instead of an apostrophe! :eek:

Redirecting worked like a charm also! :smiley:

Thanks Smiling Dragon for the quick response! :smiley: