How to add loop counter to foreach in csh

SkypeMeSM picture SkypeMeSM · Feb 22, 2011 · Viewed 66.4k times · Source

In CSH foreach loop or for loop, how can I add a loop iterator or counter which increases from 10 to 1000 with steps of 20?

Something like foreach i (1..20..5) or for (i=1;i<20;i++).

Answer

Jeremiah Willcock picture Jeremiah Willcock · Feb 22, 2011

If you have the seq command, you can use:

foreach i (`seq 1 5 20`)
  ... body ...
end

If you don't have seq, here is a version based on @csj's answer:

@ i = 1
while ($i <= 20)
  ... body ...
  @ i += 5
end