UNIX variable issue

Hi all,

Something funny happen with this code:

EXIST=`ssh batch@190.2.332.234 'if [ -f $remotePath/$fileName ]; then echo 0; else echo 1 ; fi'`
echo $EXIST

Above code will display "1".
The value of remotePath is /home/batch
The value of fileName is sample.txt

EXIST=`ssh batch@190.2.332.234 'if [ -f /home/batch/sample.txt ]; then echo 0; else echo 1 ; fi'`
echo $EXIST

Above code will display "0".

The correct result should be "0". But I dont know how come those two codes produce different result. Anybody know?

Thanks

---------- Post updated at 04:45 AM ---------- Previous update was at 04:41 AM ----------

Solved... i changed the "-f" to "-e". I dont why it works that way.. :slight_smile:

The $remotePath and $fileName variables are not set in your environment on the machine 190.2.332.234 so they end up as "/".
Try changing the line to using " speech marks so the variables get changed at the local end, e.g.:

EXIST=`ssh batch@190.2.332.234 "if [ -f $remotePath/$fileName ]; then echo 0; else echo 1 ; fi"`