Weird behavior of 'ash' with "remove prefix/suffix pattern" in parameter expansion

walter harms wharms at bfs.de
Tue Nov 22 17:17:04 UTC 2016


busybox 1.25.0
$ TEST="[ \t\r]"
$ echo ${TEST%]}
[ \t\r
$ echo ${TEST#[}
[ \t\r]

GNU bash, version 3.2.39
$ TEST="[ \t\r]"
echo ${TEST%]}
[ \t\r
echo "${TEST#[}"
 \t\r]

It seems that ${#} does not eat [:
TEST="[[[[" ; echo "${TEST#[}"
[[[[
TEST="[[[[" ; echo "${TEST#[}"
[[[

re,
 wh

Am 22.11.2016 17:18, schrieb YourFritz - framework:
> Hi,
> 
> I've found the following strange result while testing.
> 
> Running the command
> 
>     busybox sh -x -c 'test="[ \t\r]";[ ${#test} -gt 0 ] && \
> ( [ "${test#[}" = "$test" ] || [ "${test%]}" = "$test" ] ) && \
> echo true || echo false'
> 
> produces the unexpected output
> 
>     + test=[ \t\r]
>     + [ 7 -gt 0 ]
>     + [ [ \t\r] = [ \t\r] ]
>     + echo true
>     true
> 
> - the first square bracket wasn't removed by "${test#[}", the
> following comparison finds no difference and the whole (inner) term
> evaluates to "true". The "remove suffix pattern" shows the same effect.
> 
> This busybox version has been built with uClibc-0.9.33.2 for MIPS
> (34kc). Two different builds show the same behavior, one version came
> from a router vendor (AVM) in Germany and the other was made by myself.
> 
>     AVM => BusyBox v1.22.1 (2016-11-01 19:55:42 CET) multi-call binary.
>     own => BusyBox v1.24.2 (2016-09-24 17:17:47 CEST) multi-call binary.
> 
> Running the same command on x86 with a glibc-based BusyBox leads to the
> expected result:
> 
>     + test=[ \t\r]
>     + [ 7 -gt 0 ]
>     + [  \t\r] = [ \t\r] ]
>     + [ [ \t\r = [ \t\r] ]
>     + echo false
>     false
> 
> I haven't looked into the sources yet, probably it's a misbehavior of
> the underlying C library?
> 
> Have I overlooked something important here?
> 
> If it's really a problem (one case has to be wrong in my opinion *g*)
> and the proposal to fix it, is expected beside this pure notification, I
> would try to track down the issue.
> 
> 


More information about the busybox mailing list