I'd like to create a looping batch script that does slightly different things (but effectively the same), but to different targets. I know how to do it in rexx, but i'm not firm enough to pull it off in .bat.
Here's what i like to achieve (i have the loop figured out, but i don't know how to set up the target(s), so that the loop will read them one by one.
target="path1", "path2", "path3", "end"
LAB Main
if target EQ "end"
QUIT
endif
if target EQ "path1"
do stuff
endif
else
do other stuff
endif
SKIP BACK Main
Actually i've got it all figured out, the only thing missing is a way to give a variable with differing entries to the loop.
I know there is .KEY, but is there something like .KEY.1(.2,.3 etc.) That way i could simply enhance a counter (e.g. i=i+1) during the loop and simply ask for .KEY.i.
...
I know arexx is far better suited for this (that's why most of the work is done by an arexx script already). The problem is, that i need to be IN the directory when starting the arexx script, because arexx will only act on the directory it is started in, so i have to copy the rexx script to either directory and that is what i'd like to do in a batch loop.
Right now i mirrored four commands in the batch one after the other, each altering only in the path where the rexx script is copied to and started in.
The problem is, that i need to be IN the directory when starting the arexx script, because arexx will only act on the directory it is started in
This sounds to me like a misunderstanding - although I am not quite sure what you're actually trying to do, once you know where to do it.
You can always build a path in a string variable, even an absolute one, or a relative one starting with one or more '/' for that matter, and use that string variable to "address command 'cd ' || pathvar" or something, i.e. effectively set the current dir of your running script's process somewhere else.
Normally it's good practice to save your current dir first, so you can restore it at the end of the script.
I once made a file size based counter ;) I don't know if there would be other way, but if you don't have the ForEach command (on OS3, for example), then you could hack it like this (modified it to do what you asked) :P
; some paths you want to handle
setenv 1 "RAM:"
setenv 2 "T:"
setenv 3 "SYS:"
; init our counter to zero
echo "" noline > ENV:counter
; loop start
lab loop
; increase counter by one
echo "" >> ENV:counter
; read the counter value to a local variable
set i `list env:counter lformat "%L"`
; if we have a corresponding file, then do stuff and loop
if exists env:$i
; Get contents
set p `getenv $i`
; Do stuff
echo "Processing $p"
if $p eq "SYS:"
echo " Special case!"
else
echo " Normal case..."
endif
; clear variables
unsetenv $i
unset p
; jump back in the script
skip loop back
endif
; otherwise clean up and quit
unsetenv counter
unset i
And that would output:
Processing RAM:
Normal case...
Processing T:
Normal case...
Processing SYS:
Special case!