The output of iwconfig
puts the name of the access point in double quotes, which leads to some weirdness. The author of the script deals with this "artifact" in his script rather than getting rid of it right away. I suggest to remove the quotes before doing anything else. Two possible approaches would be:
$ eval moo=`iwconfig wlan0 | awk -F":" '/ESSID/' ` $ moo=`iwconfig wlan0 | awk -F":" '/ESSID/' |tr -d \"`
The first one executes the variable assignment statement "literally", while the other one removes double quotes from the output string.
The second problem with the script lies in the assumption that it is fine to use $LIST without quoting it (since the string would have contained double quotes). I think this is a mistake because the string still evaluates as two tokens:
$ moo='"aaa bbb"' $ if [ $moo = "\"aaa bbb\""];then ok;fi ash: bbb": unknown operand $ if [ "$moo" = "\"aaa bbb\"" ];then echo ok;fi ok
In order to fix this, quote the parameters in the square brackets and get rid of the escaped quotes in the second argument (because we removed them from the iwconfig output):
if [ "$LIST" = "$1" ]; then ...
Also, in order to pass a string with irregular character (space, parenthesis) as one argument to a script, just quote it:
$ autoconnect.sh "a name (with a comment)"
The last part about matching the name with grep has already been adequately answered by glenn jackman.
Note: The above was tested with BusyBox ash (1.20.2).