title: wait command in shell script
body: <pre><code>fork(){
      i=0
      count=0
      while (($count&lt;5))
      do
          fpfunction &amp;
          pid=$!
  
          #Ensure the pid is available 
          if [  -z "$pid" ]; then
          echo "IS NULL"
          else
          Array[$i]=$pid
          echo "PID is $pid"
          fi
  
          wait [$pid]
          i=$((i+1))
          count=$(( count+1 ))
      done
  
      echo "PID: ${Array[*]}"
  
  }
  </code></pre>
  
  <p>The fpfunction() only echo a string, so I dont write it here.</p>
  
  <p>My understanding to wait() is it will wait a child process to complete and then return a value. </p>
  
  <p>I put wait() in my script because I want to ensure all child processes are finished.</p>
  
  <p>However, the error occured</p>
  
  <p>not a pid or valid job spec</p>
  
  <p>Is my understanding wrong? please let me know how to fix this issue.</p>
  
  <p>Thanks a lot.</p>