Ding! ... hurrying back to keyboard ... try this! (don't have the time
to test it all)

var="ab/cd"
echo ${var/\\//xxx}
--> abxxxcd
echo "${var/\//xxx}"    (bash compatible!)
-->abxxxcd

allows to replace ? and *

var="ab*cd"
echo "${var/\*/xxx}"
-->abxxxcd

This fixes at least three problems I had in serveral startup scripts.


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

        idx = arg;
        while (1) {
                if (!(c = *arg++))
                        break;
                if (c == '\\') {
                        *idx++ = c;
                        if ((c = *arg++) == '\\' && !inquotes)
                                c = *arg++;
                        if (!c)
                                break;
                } else if (c == '/') {
                        /* Only the first '/' seen is our separator */
                        if (!repl) {
                                repl = idx + 1;
                                c = '\0';
                        }
                }
                *idx++ = c;
        }
        *idx = c; /* NUL */

        return repl;
}

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

Reply via email to