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

Denys Vlasenko vda.linux at googlemail.com
Thu Nov 24 08:28:23 UTC 2016


On Thu, Nov 24, 2016 at 9:11 AM, walter harms <wharms at bfs.de> wrote:
>
>
> Am 24.11.2016 00:38, schrieb Denys Vlasenko:
>> On Tue, Nov 22, 2016 at 6:17 PM, walter harms <wharms at bfs.de> wrote:
>>> 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#[}"
>>> [[[
>>
>> Reproduced. Looks like a bug in uclibc:
>>
>> pmatch("[","[") returns 0 "no match",
>>
>> but in glibc, it returns 1.
>
> sorry, i have tested with glibc
> ldd busybox
>         linux-vdso.so.1 =>  (0x00007fff2158a000)
>         libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007f952f623000)
>         libc.so.6 => /lib64/libc.so.6 (0x00007f952f2ca000)
>         /lib64/ld-linux-x86-64.so.2 (0x00007f952f860000)

Double-checking:

With CONFIG_CROSS_COMPILER_PREFIX="i686-" (this selects uclibc toolchain):

$ ldd busybox
    linux-gate.so.1 (0xf7785000)
    libc.so.0 => /lib/libc.so.0 (0xf7727000)
    ld-uClibc.so.0 => /lib/ld-uClibc.so.0 (0xf7721000)
$ ./busybox ash -c 'TEST="[[[[" ; echo "${TEST#[}"'
[[[[

With CONFIG_CROSS_COMPILER_PREFIX="":

$ ldd busybox
    linux-vdso.so.1 (0x00007ffdfe74c000)
    libc.so.6 => /lib64/libc.so.6 (0x00007f4dfca01000)
    /lib64/ld-linux-x86-64.so.2 (0x0000559bc2b3c000)
$ ./busybox ash -c 'TEST="[[[[" ; echo "${TEST#[}"'
[[[


More information about the busybox mailing list