title: Passing dynamic regexp via bash shell script
body: <p>I'm coding a simple bash script to pass a IP port to a regexp to an awk command. I'm looking for the port only in the Local Destination</p>
  
  <p>Here is the code:</p>
  
  <pre><code>#!/bin/bash
  s=$1
  port="/[^0-9]$s$/"
  netstat -numeric | awk -v pat="$port" '$6 == "ESTABLISHED" &amp;&amp; $4 ~ pat {print}'
  </code></pre>
  
  <p>Here is example of data.</p>
  
  <pre><code>tcp        0      0  1.9.1.1:23    1.9.2.1:54156 ESTABLISHED
  tcp        0      0  1.9.1.1:23    1.9.2.4:51376 ESTABLISHED
  tcp        0      0  1.9.1.1:23    1.9.2.1:53299 ESTABLISHED
  tcp        0      0  1.9.1.1:23    1.9.2.1:64695 ESTABLISHED
  tcp        0      0  1.9.1.1:53086 1.9.1.8:23   ESTABLISHED
  tcp        0      0  1.9.1.1:23    1.9.2.1:53296 ESTABLISHED
  </code></pre>
  
  <p>When I run the script, it returns nothing.</p>
  
  <p>When I run it manually , it returns the following:</p>
  
  <pre><code>netstat -numeric | awk '$6 == "ESTABLISHED" &amp;&amp; $4 ~ /[^0-9]23$/ {print}'
  
  tcp        0      0  1.9.1.1:23    1.9.2.1:54156 ESTABLISHED
  tcp        0      0  1.9.1.1:23    1.9.2.4:51376 ESTABLISHED
  tcp        0      0  1.9.1.1:23    1.9.2.1:53299 ESTABLISHED
  tcp        0      0  1.9.1.1:23    1.9.2.1:64695 ESTABLISHED
  tcp        0      0  1.9.1.1:23    1.9.2.1:53296 ESTABLISHED
  </code></pre>
  
  <p>Any suggestions would greatly appreciated.</p>