Pregunta

First, bash is not installed on the system I am using. So, no bash based answers please. Ash does not do ifs with Regexes.

In an ash shell script I have a list of acceptable responses:

# NB:  IFS = the default IFS = <space><tab><newline>
# 802.11 channel names
channels="1 2 3 4 5 5u 6 7 7u 8 8u 9 9u 10 10u 11 11u 2l 36 3l 40 40u 44 48
48u 4l 52 56 56u 5l 60 61 64 64u 7l 100 104 104u 108 112
112u 116 132 136 136u 140 144 144u 149 153 153u 157 161 161u 165 36l
44l 52l 60l 100l 108l 132l 140l 149l 157l 36/80 40/80 44/80 48/80 52/80 56/80 60/80
64/80 100/80 104/80 108/80 112/80 132/80 136/80 140/80 144/80 149/80 153/80 157/80 161/80"

A menu routine has returned "MENU_response" containing a possibly matching response I want to see if I got back a valid response.

for t in "$channels"; do
   echo "B     MENU_response = \"${MENU_response}\"      test = \"${t}\""
   if [ "${MENU_response}" = "${t}" ]; then
        break 
   fi
done

The echo in the loop is reposting that $t = all of $channels, which makes no sense. I have used this technique in several other places and it works fine.

Can someone tell me why this is happening? Do I need to wrap quotes around each individual channel?

¿Fue útil?

Solución

Removing the quotes around "$channels" works for me:

$ channels="1 2 3 4 5 5u 6 7 7u 8 8u 9 9u 10 10u 11 11u 2l 36 3l 40 40u 44 48
> 48u 4l 52 56 56u 5l 60 61 64 64u 7l 100 104 104u 108 112
> 112u 116 132 136 136u 140 144 144u 149 153 153u 157 161 161u 165 36l
> 44l 52l 60l 100l 108l 132l 140l 149l 157l 36/80 40/80 44/80 48/80 52/80 56/80 60/80
> 64/80 100/80 104/80 108/80 112/80 132/80 136/80 140/80 144/80 149/80 153/80 157/80 161/80"
$ for t in $channels; do echo $t; done
1
2
3
4
5 
# etc.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top