http://mtjm.eu/patches/script.diff shows one possibility of fixing it.
DEVICE_NAMES is not an array; the extra trailing whitespace makes the match fail. cat ... | grep ... | sed ... can be replaced by one invocation of sed; -r makes it use the more common extended regexp syntax. Device names contain special characters, so they need shell quoting and matching via fgrep. Since fgrep searches for lines matching any pattern line, the inner loop can be simplified. bash -ex is very useful when debugging such scripts.
pgpR8XigNAF2D.pgp
Description: PGP signature
