On Fri, Sep 3, 2010 at 11:39 PM, Harald Becker <[email protected]> wrote:
> 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;
> }
This is all good, but will it solve this?
v='a/b/c'
s='b/c'
r='e/f'
echo "${v/$s}"
echo "${v/$s/d}"
echo "${v/$s/$r}"
That's for var_bash5.tests which ash currently fails.
This can't be fixed by merely tweaking parse_sub_pattern(),
because parse_sub_pattern() gets called _after_ the expansion.
Therefore I think it's pointless to play with parse_sub_pattern()
before the more fundamental problem is fixed: the / shall be detected
_before_ the expansion step. That fix will be more intrusive and
will likely affect parse_sub_pattern() a lot.
--
vda
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox