Short: Execute cmd for every argument/file/line
Author: Thomas@Igracki.de (Thomas Igracki)
Architecture: ppc-morphos; ppc-amigaos; m68k-amigaos
Usage: Foreach FILE/S,LINE/S,Strings/M/A,DO=Command/K/A,ALL=ALLFILES/S,LF=AddLF/S,V=VERBOSE/S,FREESTACK/S,FA=FailAt/K/N
Execute "command" for every word in "strings".
A "%s" in "command" will be replaced with the current word in "strings".
If a command returned an error, the execution gets aborted!
If you specify FILE on the commandline every word in "strings" is treated as a file
incl. pattern matching! Non existing files are skipped.
f.e. Foreach FILE "ram:#?" "sys:#?" DO "echo %s"
I use it in combination with my ecx-script to compile multiple sources with one command.
Its written in AmigaE with the ecx compiler by Leif Salomonsson!
I also included a 68k and AmigaOS4 version.
fix: a small fix with OR handling
fix: Foreach didn't hold the Result2 value anymore due to recently changes
new: ENV:Foreach_LastFile holds the last processed filename
usefull f.e. if you want to get the filename which aborts the execution
new: added a FailAt/K/N option, like Shell's FailAt commmand, to change
failure limit of executed commands (0=Ok, 5=Warn, 10=Error, 20=Fail)
To NOT abort execution if only one file throws an error
Default is 10
fix: Starting Foreach with no arguments printed many bogus chars
new: added LINE/S, to do a command for every line in a file
The files are specified via the "<strings>" options.
Multiple files and pattern matching are supported and the ALL option
fix: Sometimes the ALL/S switch to return recursively all files didn't worked correct
fix: option VERBOSE/S didn't prints the argument in front of the output sometimes,
f.e. if c:Type was used
new: added FREESTACK/S option to show the free stack, only for debugging purpose
new: you can now use upto 8 "%s" in the DO option
chg: Raised stack to 32KB, cause I have some weird hits sometimes, lets see if it helps...
chg: The VERBOSE option now prints the current argument in front of the output
new: added LF=AddLF/S switch, append a LF after the commands output.
Usefull if the command doesn't outputs an LF at the end
new: added ALL=ALLFILES/S switch, to recursively scan directories, if FILE is set
fix: if FILE is set, then don't execute the command for directories
new: added a FILE/S switch, "strings" are then treated as files, incl. pattern matching!
01-Jul-13: v1.0 first release