Fwd: arrays

David Henderson dhenderson at digital-pipe.com
Thu Aug 4 21:05:54 UTC 2016


---------- Forwarded message ----------
From: David Henderson <dhenderson at digital-pipe.com>
Date: Thu, 4 Aug 2016 14:41:25 -0400
Subject: Re: arrays
To: Jody Lee Bruchon <jody at jodybruchon.com>

Thanks for the response Jody!  I understand that BB is POSIX
compliant, but didn't realize that arrays are not part of POSIX.  Is
there any chance or interest in adding slightly more than that
standard in BB?  The reason I ask is that, based on the response below
(and most likely any other responses too), the options are to bloat
(and create less readability) the shell scripts with insecure eval
statements and tons of loops to create and process individual
variables, or to bloat the OS by adding additional software (which
could also be a security risk due to the bugs in that additional
software).  Neither of those seems like a good choice.  Arrays are
commonly used today, perhaps not in the 70's :), but today they are.

Dave


On 8/4/16, Jody Lee Bruchon <jody at jodybruchon.com> wrote:
> ash (the BusyBox shell) is POSIX compliant but is not Bash compatible. To
> use arrays, you have to do some trickery with the eval command to simulate
> them with normal variables. It is not nearly as convenient as Bash arrays
> nor as easy to read, but it is workable. Essentially you maintain a counter
> yourself and when you need to refer to an array variable you do something
> like
>
> eval DRIVE$CNT=123
> eval echo DRIVE$CNT
>
> Which uses the value in CNT as part of the variable name being referenced.
>
> I haven't done this in a while so I may have something wrong, but that's the
> general idea. The alternative is of course to install Bash and not need to
> do this in the first place.
>
> On August 4, 2016 9:57:15 AM EDT, David Henderson
> <dhenderson at digital-pipe.com> wrote:
>>So I'm trying to process the attached storage devices and their
>>partitions (which get stored in arrays since the data is referenced
>>multiple times).  Since I don't know what any one particular user will
>>have, I can't create individual variables for this and use arrays.
>>I'm still looking for help with this.
>>
>>Thanks,
>>Dave
>>
>>
>>On 8/2/16, David Henderson <dhenderson at digital-pipe.com> wrote:
>>> Good morning all!  I have a script that uses arrays, but I can't seem
>>> to figure out what's going on with /bin/sh in handling them.  Is
>>there
>>> a specific way to initialize them or use them with busybox?
>>>
>>> Thanks,
>>> Dave
>>>
>>_______________________________________________
>>busybox mailing list
>>busybox at busybox.net
>>http://lists.busybox.net/mailman/listinfo/busybox
>
> --
> Sent from my Android phone with K-9 Mail. Please excuse my brevity.
>


More information about the busybox mailing list