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 <[email protected]> wrote:
> 
>>  [image: Boxbe] <https://www.boxbe.com/overview> [email protected] is not on your
>> Guest List
>> <https://www.boxbe.com/approved-list?tc_serial=21777443206&tc_rand=652426986&utm_source=stf&utm_medium=email&utm_campaign=ANNO_MWTP&utm_content=001&token=aDeOtixSIEH3%2F0Ze0cAv3ydDN957%2BNU3ojgLwj2ek%2F4gXUWcTJ0iLwUhbD5cG%2B2F&key=f6wuCr76tTrCLRy6zk1fMqykcfj899VyTLRSWEJBniU%3D>
>> | Approve sender
>> <https://www.boxbe.com/anno?tc_serial=21777443206&tc_rand=652426986&utm_source=stf&utm_medium=email&utm_campaign=ANNO_MWTP&utm_content=001&token=aDeOtixSIEH3%2F0Ze0cAv3ydDN957%2BNU3ojgLwj2ek%2F4gXUWcTJ0iLwUhbD5cG%2B2F&key=f6wuCr76tTrCLRy6zk1fMqykcfj899VyTLRSWEJBniU%3D>
>> | Approve domain
>> <https://www.boxbe.com/anno?tc_serial=21777443206&tc_rand=652426986&utm_source=stf&utm_medium=email&utm_campaign=ANNO_MWTP&utm_content=001&dom&token=aDeOtixSIEH3%2F0Ze0cAv3ydDN957%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 <
>>> [email protected]> 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
>>>>> <[email protected]
>>>>> <mailto:[email protected]>> 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
>>>>>         [email protected] <mailto:[email protected]>
>>>>>         http://lists.busybox.net/mailman/listinfo/busybox
>>>>>
>>>>>
>>>>>
>>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> busybox mailing list
>>> [email protected]
>>> http://lists.busybox.net/mailman/listinfo/busybox
>> _______________________________________________
>> busybox mailing list
>> [email protected]
>> http://lists.busybox.net/mailman/listinfo/busybox
>>
> 
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to