Retrive the value returned by a command excuted in a remote server using ssh

Hello Everybody,

I'm facing a weird problem with the awk command.

I try to retrieve in a variable the value returned by a simple ls command.
ls /export/home/tmp |tail -1 return a good value (the name of the .
But When I try to execute the same command in a remote server using ssh as follows:
ssh root@192.168.1.20 "TERM=xterm; export TERM; VAR=`ls /export/home/tmp |tail -1`; echo $VAR"
I have the following error message:
ls: cannot access /export/home/tmp: No such file or directory:mad:

Could someone help me to resolve this problem by storing the retuned valu in a variable.

Thanx a lot!!

This doesn't work that way; see why with this example:

root@somehost:/> a=3
root@somehost:/> ssh isau02 "a=1; echo $a"
3

The variable is read in your current shell, not the remote shell. Maybe use it this way:

root@somehost:/> A=`ssh isau02 "ls -1| tail -1"`
root@somehost:/> echo $A
xorg.conf.new

Hi Zaxxon,

Thanx a lot for your help.

Cheers.