title: Where is my bash arithmetic error?
body: <p>I am attempting to run the following bash script on boot (from /etc/rc.local) but the script does not get run because of the following syntax error:</p>
  
  <pre><code>+1") syntax error: invalid arithmetic operator (error token is ''
  </code></pre>
  
  <p>Here is the script in full</p>
  
  <pre><code>#!/bin/bash
  distro=$(cat /etc/issue | head -n 2 | tr -d "\n" | tr "[:upper:]" "[:lower:]")
  device=$(fdisk -l | grep -w 8e | head -n 1 | cut -c-8)
  partcount=$(fdisk -l | grep $device | sed 1d | grep -c $device)
  newpartnum=$(($partcount+1))
  startsector=$(fdisk -l | grep -w 8e | tail -1 | tr " " "\n" | sed "/^$/d" | head -n 3 | tail -1)
  newstartsector=$(($startsector+1))
  endsector=$(fdisk -l | grep sectors | head -n 1 | tr " " "\n" | tail -2 | head -n 1)
  newendsector=$(($endsector-1))
  fdisk $device &lt;&lt;EOF
  n
  p
  $newpartnum
  $newstartsector
  $newendsector
  t
  $newpartnum
  8e
  w
  EOF
  
  sed -i'.bak' '/00resize/d' /etc/rc.local
  echo "sh /root/01setup.sh" &gt;&gt; /etc/rc.local
  
  #reboot
  </code></pre>
  
  <p>I assume the error is with $(($partcount+1)) or $(($startsector+1)) but I'm not sure how.</p>