Strange behaviour/bug in ash Variable substitution

Ralf Friedl Ralf.Friedl at online.de
Sat Jun 26 14:12:32 UTC 2010


I have the following effect with this script:

$ cat /tmp/test.sh
#!/bin/sh

IP=192.168.0.1
echo "${IP//./\\.}"
echo "${IP//./\\.}"' '
echo "${IP//./\\.}"'['
echo "${IP//./\\.}["
echo "${IP//./\\\\.}["
# end

$ ash /tmp/test.sh
192\.168\.0\.1
192\.168\.0\.1
192.168.0.1[
192.168.0.1[
192\.168\.0\.1[
$ bash /tmp/test.sh
192\.168\.0\.1
192\.168\.0\.1
192\.168\.0\.1[
192\.168\.0\.1[
192\\.168\\.0\\.1[

The intent is to build a regular expression that has the dots quoted. It 
works when nothing follows the substitution (1. echo). It works when 
followed by a quoted space, or every other character I tried (2. echo). 
The quote doesn't appear when it is followed by an opening bracket, 
either in single quotes or in double quotes (3. echo and 4. echo). It 
seems that in this case extra backslashes are needed (5. echo). The 
substitution is performed, but the following bracket somehow causes an 
extra unquoting of the argument.
The results with bash are different.
BusyBox is v1.16.1.

Ralf


More information about the busybox mailing list