title: Shell script exiting the loop after calling another script
body: <p>I have a shell script s1 calling another script s2 in a loop.</p>
  
  <p>However s1 can not seem to continue the loop after s2 returns. </p>
  
  <p>Commenting out the line that calls s2 will enable the loop to continue.</p>
  
  <p>s2 does copy of one file, s1 checks conditions and copy several files using s2. </p>
  
  <p>Can anyone give a pointer what is going on here?</p>
  
  <pre><code>...
  while read line
  do
      s2 param1 param2 param3
      echo "copy done"
  done &lt; $tempfile
  
  echo "out of loop"
  ...
  </code></pre>
  
  <p>"copy done" is printed, so is "out of loop"</p>
  
  <p>Some contents in s2:</p>
  
  <pre><code>if ls -l $LOGDIR | grep -w sftp.log
  
  if ssh $USER -i $IDENTITY "ls -l $MOV_LOC"
  
  cat $TMPDIR/$TMPFILE1 | /usr/xpg4/bin/awk -v logdir=$LOGDIR -v register=$REGISTER -v rmt_cmd=$RMT_CMD -v identity=$IDENTITY '{print "scp -q -r -P 22 -i", identity, rmt_cmd ,$NF, "&gt;&gt;" , logdir "/" register , "2&gt;&amp;1"}' &gt; $TMPDIR/$TMPSCRIPT2
  
  cat $TMPDIR/$TMPFILE1 | /usr/xpg4/bin/awk -v tmpdir=$TMPDIR -v list=$TMPFILE2 '{print "digest -a sha1" , $NF , "&gt;&gt;", tmpdir "/" list}' &gt; $TMPDIR/$TMPSCRIPT1
  
  ssh $USER -i $IDENTITY "mv $REMOTE_QUEUE $MOV_LOC" &gt; $TMPDIR/$TMPFILE5
  </code></pre>