title: netcat inside a while read loop returning immediately
body: <p>I am making a menu for myself, because sometimes I need to search (Or NMAP which port).
  I want to do the same as running the command in the command line.</p>
  
  <p>Here is a piece of my code:</p>
  
  <pre><code>nmap $1 | grep open | while read line; do
      serviceport=$(echo $line | cut -d' ' -f1 | cut -d'/' -f1);
      if [ $i -eq $choice ]; then
          echo "Running command: netcat $1 $serviceport";
          netcat $1 $serviceport;
      fi;
      i=$(($i+1));
  done;
  </code></pre>
  
  <p>It is closing immediately after it scanned everything with nmap.</p>