I think the error is coming from having blank items in $gateway. Try replacing that second portion of your code with this...

 Code:
; test for multiple default gateways
if $lan AND $wlan
    ;shell command to remove route
    ;route delete 0.0.0.0 mask 0.0.0.0 192.168.2.254 if 15
    for each $item in $gateway
        if Len($item)
            $data = split($item,",")
            $route_cmd = "route delete 0.0.0.0 mask 0.0.0.0 " + $data[0] + " if " + $data[1]
        endif
    Next
endif


Edited by ShaneEP (2013-02-26 10:51 PM)