29 December 2022, 14:50 | #1 |
Registered User
Join Date: May 2013
Location: Kleppe / Norway
Posts: 255
|
Array like variable access possible in CLI scripts?
Suppose you have a number of variables and a loop counter defined at the top of a script like
set item0 "something" set item1 "something else" env count 0 Is there a way to be able to iterate through the items in a loop by using the numerical content of the counter? This would allow for a much shorter script without a lot of repeated and hard coded paragraphs, and with added flexibility. I have all the loop mechanics working, but not how to access the content of an indexed variable. $item{$count} obviously does not work, but is something equivalent possible? Thanks in advance for any suggestions. |
29 December 2022, 15:33 | #2 |
Registered User
Join Date: Jan 2002
Location: Germany
Posts: 7,001
|
get or getenv work with a constructed variable name.
Example: Code:
set item1 a set item2 b set item3 c set item4 d set count 1 lab loop echo "item $count is `get item$count`" set count `eval $count + 1` if $count not gt 4 skip back loop endif |
29 December 2022, 16:16 | #3 |
Registered User
Join Date: May 2013
Location: Kleppe / Norway
Posts: 255
|
That did it, thanks!
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Does the CPU ever access Chip RAM without being aligned to the DMA access windows? | TommoH | Coders. Asm / Hardware | 13 | 14 December 2021 13:23 |
Saving an array to File | LeCaravage | Coders. Blitz Basic | 4 | 14 February 2021 16:37 |
Creating an array gives me a Guru | Shatterhand | Coders. Blitz Basic | 14 | 13 August 2019 20:54 |
Blitz2: Pointer to array | idrougge | Coders. Blitz Basic | 3 | 26 March 2015 21:44 |
Join variable and string in scripts. | olesio | support.Apps | 3 | 31 January 2013 11:44 |
|
|