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

Rob Landley rob at landley.net
Mon Mar 30 15:45:30 PDT 2020


Bash's handling of $SECONDS is kind of inconsistent:

$ SECONDS=0; echo $SECONDS # why does this print nothing?
$ readonly SECONDS; declare -p SECONDS ; SECONDS=0
declare -ir SECONDS="6"
$ echo $SECONDS # readonly was ignored, assignment happened anyway
10
$ SECONDS=123+456 # it STARTS integer, but integer assignment sets it to 0
$ echo $SECONDS
6
$ declare -i SS
$ SS=123+456
$ echo $SS  # integer assignment works elsewhere just fine?
579

I can't be the first person to test these corner cases, can I? (Version 4.4.12
as in devuan ascii.)

The downside is I'm trying to get a test suite that both bash and toysh passes,
and to do that I'd have to reproduce it ignoring -i and ignoring -r and I kinda
dowanna?

Speaking of inconsistent, an inherited SECONDS in the environment will init
$SECONDS in a new bash instance, but will NOT init RANDOM to a reproducible
series. Is this an intentional security thing or an oversight?

Rob


More information about the Toybox mailing list