sh shell - pattern substitution bug?

Steven Honeyman stevenhoneyman at gmail.com
Fri Jan 9 21:36:10 UTC 2015


On 9 January 2015 at 19:34, Richard Moore <rich at richud.com> wrote:
> The inconsistent behaviour (below) leads me to think there some sort of
> backslash addition bug rather than a lack of function?
>
> ~ # i="a#b#c"
> ~ # echo ${i//#/':'}
> a\:b\:c
> ~ # echo ${i//#/';'}
> a;b;c
> ~ # echo ${i//#/'*'}
> a\*b\*c
> ~ # echo ${i//#/'^'}
> a^b^c

Hmm, so it is! I agree this is a bug. I did see it works OK without
the quotes though.
With the debug prints enabled:

$ echo ${i//#/'*'}
sh: subevalvar(p:'#/��*��',varname:'(null)',strloc:6,subtype:14,startloc:0,varflags:e,quotes:1)
sh: arg:'#/\*' varflags:e
sh: pattern:'#' repl:'\*'
a\*b\*c
$ echo ${i//#/*}
sh: subevalvar(p:'#/*�',varname:'(null)',strloc:6,subtype:14,startloc:0,varflags:e,quotes:1)
sh: arg:'#/*' varflags:e
sh: pattern:'#' repl:'*'
a*b*c
$ echo ${i//#/'^'}
sh: subevalvar(p:'#/�^��',varname:'(null)',strloc:6,subtype:14,startloc:0,varflags:e,quotes:1)
sh: arg:'#/^' varflags:e
sh: pattern:'#' repl:'^'
a^b^c
$ echo ${i//#/^}
sh: subevalvar(p:'#/^�',varname:'(null)',strloc:6,subtype:14,startloc:0,varflags:e,quotes:1)
sh: arg:'#/^' varflags:e
sh: pattern:'#' repl:'^'
a^b^c

Hopefully a quick fix for someone familiar with the ash code.


Thanks,
Steven


More information about the busybox mailing list