Nick Rout wrote:
how do i do a simple for...next loopCreate a file 'repeat' vis:
I want to iterate a loop n times, i want to hand n via a shell parameter
like
=======%======
#!/bin/bash
START=$1
INCR=$2
LIMIT=$3
for ((a=START; a <= LIMIT ; a=a+INCR)) # Note use of double parens & no $s before var names.
do
echo -n "$a "
done
======%======
Put 'repeat' in your PATH and make it executable.
Use it thus, substituting "echo $n" with whatever you want:-
for n in `repeat 10 2 20`; do echo $n; done # To get the even numbers between 10 and 20 inclusive
Note Bene: _REQUIRES_ the use of bash because this is a Chet Remy 'word-of-mouth' feature, won't work with sh.
As others have suggested you might care to look at a scripting language vis:-
ruby, python, perl, and awk, in order of preference.
For real grunt at the tip of the finger, smalltalk, but the learning curve is a vertical cliff with an over-hang.
I'm about 2 foot 6 inches off the shingle. :-)
--
C . S.
