| Summary: | ash's ${var/pattern/repl} is buggy | ||
|---|---|---|---|
| Product: | Busybox | Reporter: | Marco Clocchiatti <ziapannocchia> |
| Component: | Standard Compliance | Assignee: | unassigned |
| Status: | RESOLVED FIXED | ||
| Severity: | normal | CC: | busybox-cvs, busybox.20.bastian, sbrabec |
| Priority: | P5 | ||
| Version: | 1.22.x | ||
| Target Milestone: | --- | ||
| Hardware: | All | ||
| OS: | Linux | ||
| Host: | Target: | ||
| Build: | |||
*** Bug 2281 has been marked as a duplicate of this bug. *** From bug 2281 ============= There was a bug in expansion of star inside parameter in expressions like ${FOO//\\*/-star-}. In bash 2 and lower two backslashes were eaten for escaping of star. Since bash 3 the bug is fixed. The fix introduced a small change of the behavior (one backslash escapes second backslash). Also zsh already migrated to the fixed behavior. Busybox exactly follows (at least in version 1.13) the bash 2 behavior considered as broken. It would be nice to migrate it to the fixed behavior. Example: FOO="a*b\\*c" ; echo ${FOO//\\*/-backslashstar-} Bash 2, busybox: a-backslashstar-b-\backslashstar-c Bash 3, Bash 4, zsh: a*b-backslashstar- --------------------- Fixed in git. While at it, found and quashed two more bugs. However, quoted version: FOO="a*b\\*c"; echo "${FOO//\\*/-backslashstar-}" is still broken, and is _hard_ to fix. There is now a testcase for it: Go to busybox/shell/ash_test in buld tree and run "run-all". Examine ash-vars-var_bash4.tests.fail to see quoted expansion error. the testcase
{{{
# var='/dev/ram0'
# echo ${var////-}
/dev/ram0
# should output: '-dev-ram0'
}}}
is still not working. checked with git 1eafd4494706c21a87dc66e4e0afa8799b576cb5 from 2015-mar-23 and release v1.22.1 - it should also be added to 'shell/ash_test/ash-vars/'.
thanks for your work - Bastian Bittorf
Fixed in git. |
s939 ~ # chroot busybox bin/sh / # busybox|head -n1 BusyBox v1.15.3 (2010-09-20 13:10:56 CEST) multi-call binary / # find . -exec ls -l {} \; drwxr-xr-x 2 0 0 2048 Oct 10 23:49 bin -rwxr-xr-x 1 0 0 2062112 Sep 20 11:11 busybox lrwxrwxrwx 1 0 0 7 Oct 10 23:49 sh -> busybox -rwxr-xr-x 1 0 0 2062112 Sep 20 11:11 ./bin/busybox lrwxrwxrwx 1 0 0 7 Oct 10 23:49 ./bin/sh -> busybox / # #example with pattern containing slashes: / # var="/dev/ram0" / # echo ${var////-} /dev/ram0 / # #example with pattern not containing slashes: / # var="|dev|ram0" / # echo ${var//|/-} -dev-ram0 / # exit