title: bash: while read loop - stop if there is variable sshpass
body: <p>i have a problem with my bash script. I read line by line the variable lvm_path_exec, that works. I confirmed it with echo "lvmpath".
  But as soon as i place a sshpass command into the while statement the script only process the first line which got grepped.</p>
  
  <p>If there is no sshpass command all lines of lvmpath_exec get processed.</p>
  
  <p>Do you see the error? </p>
  
  <pre><code>lvmpath_exec=$(sshpass -p "${password[$i]}"  ssh ${user[$i]}@${ip[$i]} -p ${port[$i]}  lvdisplay | grep datatest -A 3 | grep Path | awk '{ print $3 }') 
  
  echo "$lvmpath_exec" | while read lvmpath
  do
  lvmname=datatest
  snap=_snapshot
  snapname=$lvmname$snap
  
  lvcreate=$(sshpass -p "${password[$i]}"  ssh ${user[$i]}@${ip[$i]} -p ${port[$i]}  lvcreate -L20G -s -n $snapname $lvmpath)
  
  snap_path=$(sshpass -p "${password[$i]}"  ssh ${user[$i]}@${ip[$i]} -p ${port[$i]}  lvdisplay | grep $snapname -A 3 | grep Path | awk '{ print $3 }')
  
  transfer=$(sshpass -p "${password[$i]}"  ssh ${user[$i]}@${ip[$i]} -p ${port[$i]} "dd if=$snap_path | gzip -c" &gt; /tmp/$snapname)
  
  delsnap=$(sshpass -p "${password[$i]}"  ssh ${user[$i]}@${ip[$i]} -p ${port[$i]} lvremove -f $snap_path)
  
  done
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I fixed it:
  replace</p>
  
  <pre><code>echo "$lvmpath_exec" | while read lvmpath
  </code></pre>
  
  <p>with</p>
  
  <pre><code>for lvmpath in $lvmpath_exec
  </code></pre>
  
  <p>But shouldnt it work with while read too?</p>