title: Syntax error in expression (error token is "INPUT (policy ACCEPT) | cut -d ' ' -f1)
body: <p>Hi I'am recently started learning bash scripts, since I'm quite &quot;green&quot; so to speak I hope I can get some help. I have this problem that I just can't seem to figure out on my own. I want this program to read through every line to check if there are any iptables rules for a given IP address. If there is: Take the number of the line, and then change or delete it with the iptables -R INPUT $lineNumberHere -s $IP_ADDRESS -j $newPolicy.</p>
  <p>However the program starts reading the first lines and registers the line number as a &quot;Chain&quot; and &quot;num&quot; which causes the error. Is there a method of bypassing these two lines?</p>
  <p>Just to clarify. I am running the program as root</p>
  <pre><code>
  # The IP address is listen in rules
  
          # Find the line number of the rule
          echo &quot;&quot;
          echo &quot;The IP allready has a rule in iptables&quot;
          iptables -L INPUT --line-numbers | while read line; do
                  echo &quot;&quot;
                  echo &quot;Checking line: $line&quot;
                  LINE_NUMBER=$(($line | cut -d &quot; &quot; -f1))
                  BANNED_IP=$(($line | cut -d &quot; &quot; -f4 | cut -d &quot;/&quot; -f1))
                  re='^[0-9]+$'
                  if [[ &quot;$LINE_NUMBER&quot; =~ $re ]]; then
  
                          echo &quot;Line nr. $LINE_NUMBER&quot;
                          if [ &quot;$IP_ADDRESS&quot;=&quot;$BANNED_IP&quot; ]; then
                                  echo &quot;Changing status to BANNED&quot;
                                  iptables -R INPUT &quot;$LINE_NUMBER&quot; -s &quot;$IP_ADDRESS&quot; -j DROP
                          fi
                  else
                          echo &quot;error: Not a number&quot; &gt;&amp;2
                          continue;
  
                  fi
  
          done
  
  
  </code></pre>