[Toybox] Would someone please explain what bash is doing here?

Rob Landley rob at landley.net
Fri Mar 6 04:08:24 PST 2020


Is it just me, or is bash's unquoted $@ processing with a non-whitespace IFS
only retaining blank arguments when they're followed by another argument (even
if that one is blank)?

$ func() { bash -c 'IFS=x; for i in $@; do echo =$i=; done' blah "$@"; }
$ func one "" two
=one=
==
=two=
$ func one ""
=one=
$ func "" two
==
=two=
$ func "" ""
==

(I mean, it could be worse. Busybox ash is _never_ retaining zero length
arguments here. But I'm trying to figure out what logic bash is using, and not
finding a coherent design idea. Is this a bug, or did they mean to do it? If
they meant it, _why_?)

Rob

P.S. I dug up bash 2.05b and at least it's been CONSISTENT for 18 years, so I
guess that's something? But... why?

P.P.S. As far as I can tell, $@ and $* behave the same unquoted, and that's the
codepath I'm currently trying to implement.



More information about the Toybox mailing list