Issue in Variable in SSH

Friends,
I want to write a script. The logic follows

  1. Script starts
  2. SSH to Remote Machine and check whether /home/testUser dir is there or not.
  3. If it is there, am assigning a value to a variable. else not
  4. If the variable is set, the do the copy from remote machine to my local machine using scp.

Here, i can not get the value of the variable in shell script.
For ex,
ssh -q REMOTE_SERVER "if [ -d /home/testUser ]; then FLAG=YES fi"
echo $FLAG

in the above case, i can not able to print the value "YES"

My doubt is can we get the value of the variable that we set inside SSH?
Thanks in advance

  1. that's what's best ^^
ssh REMOTE '[ -d /home/testUser ]' && FLAG=YES
  1. done
  2. you'd better scp from your local
scp REMOTE:/home/testUser/whatever LOCALHOST:/whereever

Thank you so much