Hallo Denny!
> Unfortunately ${var/pattern/repl} in ash is a bad hack. I looked at
> it. It's hard to fix.

I got a hack to the hack ... but that works :-)

It protects the slash, if it is in a range specification [/], so that
slash is ignored as a pattern/repl separator and the next slash is used.

static char *
parse_sub_pattern(char *arg, int inquotes)
{
        char *idx, *repl = NULL;
        unsigned char c, rg = 0;

        idx = arg;
        while (1) {
                c = *arg;
                if (!c)
                        break;
                if (c == '[') rg++;
                if (c == ']') rg--;
                if (c == '/' && rg == 0) {
                        /* Only the first '/' seen is our separator */
                        if (!repl) {
                                repl = idx + 1;
                                c = '\0';
                        }
                }
                *idx++ = c;
                if (!inquotes && c == '\\' && arg[1] == '\\')
                        arg++; /* skip both \\, not just first one */
                arg++;
        }
        *idx = c; /* NUL */

        return repl;
}


VAR="ab/cd"
echo ${VAR/[\/]/xxx}
--> abxxxcd

busybox ash and bash

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to