title: shell script to wait for gunzip to complete before going to next line
body: <p>I created a shell script to loop through some files in a directory, unzip them, add in a date field, zip them back up, and then move them to the hadoop file system. But, when I run the script, it seems to go right to the next line without waiting for gunzip to complete. How do I tell it to wait for it to complete before moving to the next line?</p>
  
  <pre><code>FILENAME="/datatst/toproc/*"
  
  for i in $FILENAME
  do
      echo "file name is: " $i
      FILENAMEv2=$(basename "${i}" .gz )
      echo "Stripped file name is: " $FILENAMEv2
      DATEPART=$(echo $i| cut -d"." -f1| cut -d"-" -f2-)
      echo "Datepart is: " $DATEPART
      FileDir="/datatst/unzip/$FILENAMEv2"
      echo "unzip directory file is: " $FileDir
      echo "unzipping file..."
      gunzip $i &gt; -c $FileDir &amp;&amp; trash $i
      echo "unzipping done..."
      echo "sed operation begin..."
      sed -i 's/^/'$DATEPART' /g' $FileDir
      echo "sed operation done..."
      echo "zip operation begin..."
      gzip $FileDir -c &gt; /datatst/tomove/$i &amp;&amp; trash $FileDir
      su hadoop fs -put /datatst/tomove/$i /user/hdfs/
  done
  </code></pre>