[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: How to do array operation in busybox
From:       Pratik Prajapati <pratik.prajapati12 () gmail ! com>
Date:       2015-06-26 12:35:11
Message-ID: CAHNg1SoFdwYPma=2Avjvb_4sP-37pzq1JrNc8YjTi2x+xUAPsg () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Thanks

On Fri, Jun 26, 2015 at 5:08 PM, walter harms <wharms@bfs.de> wrote:

> 
> 
> Am 26.06.2015 13:15, schrieb Pratik Prajapati:
> > I tried your solution but couldn't print that array:
> > 
> > for index in 1 2 3 ; do
> > eval echo \$LST$index
> > done
> > 
> > 
> 
> yes, because it builds a string and it has no need for eval
> 
> LST=""
> for index in 1 2 3
> do
> LST=$LST" "$index
> done
> 
> echo "LST= " $LST
> 
> should result in:
> 
> LST= 1 2 3
> 
> the next trick is to use
> set -- $LST
> now you can access via $1 $2 $3 ...
> 
> if that is a good idea depend on the program itself.
> 
> re,
> wh
> 
> > 
> > On Fri, Jun 26, 2015 at 3:27 PM, walter harms <wharms@bfs.de> wrote:
> > 
> > > [image: Boxbe] <https://www.boxbe.com/overview> wharms@bfs.de is not
> on your
> > > Guest List
> > > <
> https://www.boxbe.com/approved-list?tc_serial=21777443206&tc_rand=652426986&utm_sour \
> ce=stf&utm_medium=email&utm_campaign=ANNO_MWTP&utm_content=001&token=aDeOtixSIEH3%2F \
> 0Ze0cAv3ydDN957%2BNU3ojgLwj2ek%2F4gXUWcTJ0iLwUhbD5cG%2B2F&key=f6wuCr76tTrCLRy6zk1fMqykcfj899VyTLRSWEJBniU%3D
> 
> > 
> > > > Approve sender
> > > <
> https://www.boxbe.com/anno?tc_serial=21777443206&tc_rand=652426986&utm_source=stf&ut \
> m_medium=email&utm_campaign=ANNO_MWTP&utm_content=001&token=aDeOtixSIEH3%2F0Ze0cAv3y \
> dDN957%2BNU3ojgLwj2ek%2F4gXUWcTJ0iLwUhbD5cG%2B2F&key=f6wuCr76tTrCLRy6zk1fMqykcfj899VyTLRSWEJBniU%3D
> 
> > 
> > > > Approve domain
> > > <
> https://www.boxbe.com/anno?tc_serial=21777443206&tc_rand=652426986&utm_source=stf&ut \
> m_medium=email&utm_campaign=ANNO_MWTP&utm_content=001&dom&token=aDeOtixSIEH3%2F0Ze0c \
> Av3ydDN957%2BNU3ojgLwj2ek%2F4gXUWcTJ0iLwUhbD5cG%2B2F&key=f6wuCr76tTrCLRy6zk1fMqykcfj899VyTLRSWEJBniU%3D
> 
> > 
> > > 
> > > 
> > > 
> > > Am 26.06.2015 11:07, schrieb Pratik Prajapati:
> > > > Thanks. Your solution is very useful.
> > > > 
> > > 
> > > a more shell like solution is simple using a $IFS separated list
> > > and the power of set but if you have sparse values and you need the gaps
> > > you are better of with this solution.
> > > 
> > > For the example you could do something like:
> > > LST=""
> > > for NAME in ARG
> > > do
> > > LST=$LST" "$NAME
> > > done
> > > 
> > > just my 2 cents,
> > > re,
> > > wh
> > > 
> > > 
> > > > On Fri, Jun 26, 2015 at 12:01 PM, Sven-Göran Bergh <
> > > > sgb-list+busybox@systemaxion.se> wrote:
> > > > 
> > > > > On 06/26/2015 07:59 AM, Pratik Prajapati wrote:
> > > > > 
> > > > > > I tried one method and was unable to correct it. Can you give me the
> > > > > > correct method ?
> > > > > > 
> > > > > > On Fri, Jun 26, 2015 at 11:25 AM, Sven-Göran Bergh
> > > > > > <sgb-list+busybox@systemaxion.se
> > > > > > <mailto:sgb-list+busybox@systemaxion.se>> wrote:
> > > > > > 
> > > > > > Hi Patrik
> > > > > > 
> > > > > > On 06/26/2015 07:49 AM, Pratik Prajapati wrote:
> > > > > > 
> > > > > > Hi,
> > > > > > 
> > > > > > I am working on LTP-DDT project (
> > > > > > https://github.com/rogerq/ltp-ddt)
> > > > > > which i cross-compiled for my target and my target uses
> > > busybox.
> > > > > > But
> > > > > > running it on my target gives me error as array operation is
> > > not
> > > > > > supported in busybox.
> > > > > > 
> > > > > > I have attached script with this mail.
> > > > > > 
> > > > > > I am getting error for :
> > > > > > 
> > > > > > sh: /opt/ltp/testcases/bin/ddt/common/common.sh: line 305:
> > > > > > syntax error:
> > > > > > bad substitution
> > > > > > 
> > > > > > I tried this:
> > > > > > 
> > > > > > > 305: shift
> > > > > > 306: index=0
> > > > > > 307: for  arg;
> > > > > > 308: do
> > > > > > 309:   x[$index]=$arg
> > > > > > 310:   ((index++))
> > > > > > 311: done
> > > > > > 
> > > > > 
> > > > > I am afraid that the work around is quite ugly. In this case
> > > > > you may use the evil eval:
> > > > > 
> > > > > index=0
> > > > > for arg;
> > > > > do
> > > > > eval x${index}=$arg
> > > > > eval printf "x%s:\\\t%s\\\n" "${index}" "\$x${index}"
> > > > > ((index++))
> > > > > done
> > > > > 
> > > > > Yes, I know it is ugly and I said so.
> > > > > Arrays are one of the things I miss the most in ash.
> > > > > 
> > > > > Brgds
> > > > > /S-G
> > > > > 
> > > > > 
> > > > > > but i got error:|  syntax error: unexpected "(" (expecting
> > > "}")
> > > > > > 
> > > > > > Also couldn't found any solution on google.
> > > > > > 
> > > > > > How to make it work on busybox. Please help.
> > > > > > 
> > > > > > 
> > > > > > Arrays is a bash feature, it is not supported by ash or standard
> > > > > > shells. So unfortunately the short answer is that it does not
> work.
> > > > > > However there are often ways to rework a script to avoid arrays.
> > > > > > 
> > > > > > Brgds
> > > > > > /S-G
> > > > > > 
> > > > > > 
> > > > > > Thanks,
> > > > > > 
> > > > > > Pratik
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > > _______________________________________________
> > > > > > busybox mailing list
> > > > > > busybox@busybox.net <mailto:busybox@busybox.net>
> > > > > > http://lists.busybox.net/mailman/listinfo/busybox
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > 
> > > > 
> > > > 
> > > > 
> > > > _______________________________________________
> > > > busybox mailing list
> > > > busybox@busybox.net
> > > > http://lists.busybox.net/mailman/listinfo/busybox
> > > _______________________________________________
> > > busybox mailing list
> > > busybox@busybox.net
> > > http://lists.busybox.net/mailman/listinfo/busybox
> > > 
> > 
> 


[Attachment #5 (text/html)]

<div dir="ltr">Thanks<br></div><div class="gmail_extra"><br><div \
class="gmail_quote">On Fri, Jun 26, 2015 at 5:08 PM, walter harms <span \
dir="ltr">&lt;<a href="mailto:wharms@bfs.de" \
target="_blank">wharms@bfs.de</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><span class=""><br> <br>
Am 26.06.2015 13:15, schrieb Pratik Prajapati:<br>
&gt; I tried your solution but couldn&#39;t print that array:<br>
&gt;<br>
&gt; for index in 1 2 3 ; do<br>
&gt;           eval echo \$LST$index<br>
&gt; done<br>
&gt;<br>
&gt;<br>
<br>
</span>yes, because it builds a string and it has no need for eval<br>
<br>
LST=&quot;&quot;<br>
<span class="">for index in 1 2 3<br>
  do<br>
</span>     LST=$LST&quot; &quot;$index<br>
  done<br>
<br>
echo &quot;LST= &quot; $LST<br>
<br>
should result in:<br>
<br>
LST= 1 2 3<br>
<br>
the next trick is to use<br>
set -- $LST<br>
now you can access via $1 $2 $3 ...<br>
<br>
if that is a good idea depend on the program itself.<br>
<br>
re,<br>
   wh<br>
<br>
&gt;<br>
<span class="">&gt; On Fri, Jun 26, 2015 at 3:27 PM, walter harms &lt;<a \
href="mailto:wharms@bfs.de">wharms@bfs.de</a>&gt; wrote:<br> &gt;<br>
</span>&gt;&gt;   [image: Boxbe] &lt;<a href="https://www.boxbe.com/overview" \
rel="noreferrer" target="_blank">https://www.boxbe.com/overview</a>&gt; <a \
href="mailto:wharms@bfs.de">wharms@bfs.de</a> is not on your<br> &gt;&gt; Guest \
List<br> &gt;&gt; &lt;<a \
href="https://www.boxbe.com/approved-list?tc_serial=21777443206&amp;tc_rand=652426986& \
amp;utm_source=stf&amp;utm_medium=email&amp;utm_campaign=ANNO_MWTP&amp;utm_content=001 \
&amp;token=aDeOtixSIEH3%2F0Ze0cAv3ydDN957%2BNU3ojgLwj2ek%2F4gXUWcTJ0iLwUhbD5cG%2B2F&amp;key=f6wuCr76tTrCLRy6zk1fMqykcfj899VyTLRSWEJBniU%3D" \
rel="noreferrer" target="_blank">https://www.boxbe.com/approved-list?tc_serial=2177744 \
3206&amp;tc_rand=652426986&amp;utm_source=stf&amp;utm_medium=email&amp;utm_campaign=AN \
NO_MWTP&amp;utm_content=001&amp;token=aDeOtixSIEH3%2F0Ze0cAv3ydDN957%2BNU3ojgLwj2ek%2F \
4gXUWcTJ0iLwUhbD5cG%2B2F&amp;key=f6wuCr76tTrCLRy6zk1fMqykcfj899VyTLRSWEJBniU%3D</a>&gt;<br>
 &gt;&gt; | Approve sender<br>
&gt;&gt; &lt;<a href="https://www.boxbe.com/anno?tc_serial=21777443206&amp;tc_rand=652 \
426986&amp;utm_source=stf&amp;utm_medium=email&amp;utm_campaign=ANNO_MWTP&amp;utm_cont \
ent=001&amp;token=aDeOtixSIEH3%2F0Ze0cAv3ydDN957%2BNU3ojgLwj2ek%2F4gXUWcTJ0iLwUhbD5cG%2B2F&amp;key=f6wuCr76tTrCLRy6zk1fMqykcfj899VyTLRSWEJBniU%3D" \
rel="noreferrer" target="_blank">https://www.boxbe.com/anno?tc_serial=21777443206&amp; \
tc_rand=652426986&amp;utm_source=stf&amp;utm_medium=email&amp;utm_campaign=ANNO_MWTP&a \
mp;utm_content=001&amp;token=aDeOtixSIEH3%2F0Ze0cAv3ydDN957%2BNU3ojgLwj2ek%2F4gXUWcTJ0 \
iLwUhbD5cG%2B2F&amp;key=f6wuCr76tTrCLRy6zk1fMqykcfj899VyTLRSWEJBniU%3D</a>&gt;<br> \
&gt;&gt; | Approve domain<br> &gt;&gt; &lt;<a \
href="https://www.boxbe.com/anno?tc_serial=21777443206&amp;tc_rand=652426986&amp;utm_s \
ource=stf&amp;utm_medium=email&amp;utm_campaign=ANNO_MWTP&amp;utm_content=001&amp;dom& \
amp;token=aDeOtixSIEH3%2F0Ze0cAv3ydDN957%2BNU3ojgLwj2ek%2F4gXUWcTJ0iLwUhbD5cG%2B2F&amp;key=f6wuCr76tTrCLRy6zk1fMqykcfj899VyTLRSWEJBniU%3D" \
rel="noreferrer" target="_blank">https://www.boxbe.com/anno?tc_serial=21777443206&amp; \
tc_rand=652426986&amp;utm_source=stf&amp;utm_medium=email&amp;utm_campaign=ANNO_MWTP&a \
mp;utm_content=001&amp;dom&amp;token=aDeOtixSIEH3%2F0Ze0cAv3ydDN957%2BNU3ojgLwj2ek%2F4 \
gXUWcTJ0iLwUhbD5cG%2B2F&amp;key=f6wuCr76tTrCLRy6zk1fMqykcfj899VyTLRSWEJBniU%3D</a>&gt;<br>
 <div class="HOEnZb"><div class="h5">&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; Am 26.06.2015 11:07, schrieb Pratik Prajapati:<br>
&gt;&gt;&gt; Thanks. Your solution is very useful.<br>
&gt;&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; a more shell like solution is simple using a $IFS separated list<br>
&gt;&gt; and the power of set but if you have sparse values and you need the gaps<br>
&gt;&gt; you are better of with this solution.<br>
&gt;&gt;<br>
&gt;&gt; For the example you could do something like:<br>
&gt;&gt; LST=&quot;&quot;<br>
&gt;&gt; for NAME in ARG<br>
&gt;&gt; do<br>
&gt;&gt;              LST=$LST&quot; &quot;$NAME<br>
&gt;&gt; done<br>
&gt;&gt;<br>
&gt;&gt; just my 2 cents,<br>
&gt;&gt; re,<br>
&gt;&gt;   wh<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;&gt; On Fri, Jun 26, 2015 at 12:01 PM, Sven-Göran Bergh &lt;<br>
&gt;&gt;&gt; <a href="mailto:sgb-list%2Bbusybox@systemaxion.se">sgb-list+busybox@systemaxion.se</a>&gt; \
wrote:<br> &gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; On 06/26/2015 07:59 AM, Pratik Prajapati wrote:<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; I tried one method and was unable to correct it. Can you give me \
the<br> &gt;&gt;&gt;&gt;&gt; correct method ?<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; On Fri, Jun 26, 2015 at 11:25 AM, Sven-Göran Bergh<br>
&gt;&gt;&gt;&gt;&gt; &lt;<a \
href="mailto:sgb-list%2Bbusybox@systemaxion.se">sgb-list+busybox@systemaxion.se</a><br>
 &gt;&gt;&gt;&gt;&gt; &lt;mailto:<a \
href="mailto:sgb-list%2Bbusybox@systemaxion.se">sgb-list+busybox@systemaxion.se</a>&gt;&gt; \
wrote:<br> &gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;        Hi Patrik<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;        On 06/26/2015 07:49 AM, Pratik Prajapati wrote:<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;              Hi,<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;              I am working on LTP-DDT project (<br>
&gt;&gt;&gt;&gt;&gt; <a href="https://github.com/rogerq/ltp-ddt" rel="noreferrer" \
target="_blank">https://github.com/rogerq/ltp-ddt</a>)<br> &gt;&gt;&gt;&gt;&gt;       \
which i cross-compiled for my target and my target uses<br> &gt;&gt; busybox.<br>
&gt;&gt;&gt;&gt;&gt; But<br>
&gt;&gt;&gt;&gt;&gt;              running it on my target gives me error as array \
operation is<br> &gt;&gt; not<br>
&gt;&gt;&gt;&gt;&gt;              supported in busybox.<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;              I have attached script with this mail.<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;              I am getting error for :<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;              sh: /opt/ltp/testcases/bin/ddt/common/common.sh: \
line 305:<br> &gt;&gt;&gt;&gt;&gt;              syntax error:<br>
&gt;&gt;&gt;&gt;&gt;              bad substitution<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;              I tried this:<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;              |305: shift<br>
&gt;&gt;&gt;&gt;&gt;              306: index=0<br>
&gt;&gt;&gt;&gt;&gt;              307: for   arg;<br>
&gt;&gt;&gt;&gt;&gt;              308: do<br>
&gt;&gt;&gt;&gt;&gt;              309:     x[$index]=$arg<br>
&gt;&gt;&gt;&gt;&gt;              310:     ((index++))<br>
&gt;&gt;&gt;&gt;&gt;              311: done<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; I am afraid that the work around is quite ugly. In this case<br>
&gt;&gt;&gt;&gt; you may use the evil eval:<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; index=0<br>
&gt;&gt;&gt;&gt; for arg;<br>
&gt;&gt;&gt;&gt; do<br>
&gt;&gt;&gt;&gt;              eval x${index}=$arg<br>
&gt;&gt;&gt;&gt;              eval printf &quot;x%s:\\\t%s\\\n&quot; \
&quot;${index}&quot; &quot;\$x${index}&quot;<br> &gt;&gt;&gt;&gt;              \
((index++))<br> &gt;&gt;&gt;&gt; done<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Yes, I know it is ugly and I said so.<br>
&gt;&gt;&gt;&gt; Arrays are one of the things I miss the most in ash.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Brgds<br>
&gt;&gt;&gt;&gt; /S-G<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;               |but i got error:|   syntax error: unexpected \
&quot;(&quot; (expecting<br> &gt;&gt; &quot;}&quot;)<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;              Also couldn&#39;t found any solution on google.<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;              How to make it work on busybox. Please help.<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;        Arrays is a bash feature, it is not supported by ash or \
standard<br> &gt;&gt;&gt;&gt;&gt;        shells. So unfortunately the short answer is \
that it does not work.<br> &gt;&gt;&gt;&gt;&gt;        However there are often ways \
to rework a script to avoid arrays.<br> &gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;        Brgds<br>
&gt;&gt;&gt;&gt;&gt;        /S-G<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;              Thanks,<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;              Pratik<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;              _______________________________________________<br>
&gt;&gt;&gt;&gt;&gt;              busybox mailing list<br>
&gt;&gt;&gt;&gt;&gt;              <a \
href="mailto:busybox@busybox.net">busybox@busybox.net</a> &lt;mailto:<a \
href="mailto:busybox@busybox.net">busybox@busybox.net</a>&gt;<br> \
&gt;&gt;&gt;&gt;&gt;              <a \
href="http://lists.busybox.net/mailman/listinfo/busybox" rel="noreferrer" \
target="_blank">http://lists.busybox.net/mailman/listinfo/busybox</a><br> \
&gt;&gt;&gt;&gt;&gt;<br> &gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; _______________________________________________<br>
&gt;&gt;&gt; busybox mailing list<br>
&gt;&gt;&gt; <a href="mailto:busybox@busybox.net">busybox@busybox.net</a><br>
&gt;&gt;&gt; <a href="http://lists.busybox.net/mailman/listinfo/busybox" \
rel="noreferrer" target="_blank">http://lists.busybox.net/mailman/listinfo/busybox</a><br>
 &gt;&gt; _______________________________________________<br>
&gt;&gt; busybox mailing list<br>
&gt;&gt; <a href="mailto:busybox@busybox.net">busybox@busybox.net</a><br>
&gt;&gt; <a href="http://lists.busybox.net/mailman/listinfo/busybox" rel="noreferrer" \
target="_blank">http://lists.busybox.net/mailman/listinfo/busybox</a><br> \
&gt;&gt;<br> &gt;<br>
</div></div></blockquote></div><br></div>



_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic