Bash script to set up an ad hoc wireless network
Not answering your actual question, but offering a couple of code comments:

use cd -- "$(dirname -- "$0")"


if the script is in the PATH and someone just enters the script name, you will try to cd to the (probably non-existant) "script name" directory in the current dir.


use grep -q $DEVICE


that is a bit speedier since, if it finds a match, it exits immediately instead of having to read the entire input looking for all matches.