English Amiga Board


Go Back   English Amiga Board > Support > support.AmigaOS

 
 
Thread Tools
Old 29 December 2022, 14:50   #1
Yulquen74
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.
Yulquen74 is offline  
Old 29 December 2022, 15:33   #2
thomas
Registered User
 
thomas's Avatar
 
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
thomas is offline  
Old 29 December 2022, 16:16   #3
Yulquen74
Registered User
 
Join Date: May 2013
Location: Kleppe / Norway
Posts: 255
That did it, thanks!
Yulquen74 is offline  
 


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 06:08.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.06393 seconds with 15 queries