title: how to set bash variable in expect or return variable from expect to bash
body: <pre><code> VAR=$(expect -c ' 
   spawn ssh-copy-id -i '"$SSH_KEY_PATH_PUB $REMOTE_HOST_USER@$REMOTE_HOST_IP"' 
   expect "*?assword:*" 
   send "'"$REMOTE_HOST_PASSWD"'\r"; 
   expect {
   "Permission denied, please try again."{ 
   send user "Wrong pass" 
   exit 5
   }
   }
   ')
   echo "$VAR"
  </code></pre>
  
  <p>UPDATE:
  So I need the exit condition when the code enters the Permission denied block.I am lookin at $?</p>
  
  <p>But it is 0 because "$VAR" runs succesfully.</p>
  
  <p>So I need a an integer return value when it enters Permission denied block</p>