title: how to assign terminal variable from previous command's output
body: <p>I'm very very new to the terminal script world.  Here's what I want to do:</p>
  
  <pre><code>1) Find out the process that's using a given port (8000 in this case)
  2) Kill that process
  </code></pre>
  
  <p>Pretty simple.  I can do it manually using:</p>
  
  <pre><code>lsof -i tcp:8000 -- get the PID of what's using the port
  kill -9 $PID -- terminate the app using the port
  </code></pre>
  
  <p>For reference, here's exactly what gets returned when using lsof -i tcp:8000</p>
  
  <pre><code>COMMAND   PID       USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
  php     94735     MyUser    5u  IPv6 0x9fbd127eb623aacf      0t0  TCP localhost:irdmi (LISTEN)
  </code></pre>
  
  <p>Here's my problem: <strong>how do I capture the PID value from <code>lsof -i tcp:8000</code> so that I can use that variable for the next command?</strong>  I know how to create variable that I assign... just not ones that are dynamically made.</p>