Bourne Shell For i in (seq)

loops, scripting, sh, shell

Solution

try

for i in 1 10 15 20
do
   echo "do something with $i"
done

else if you have recent Solaris, there is bash 3 at least. for example this give range from 1 to 10 and 15 to 20

for i in {1..10} {15..20}
do
  echo "$i"
done

OR use tool like nawk

for i in `nawk 'BEGIN{ for(i=1;i<=10;i++) print i}'`
do
  echo $i
done

OR even the while loop

while [ "$s" -lt 10 ]; do s=`echo $s+1|bc`; echo $s; done

Problem

I want to write a loop in Bourne shell which iterates a specific set of numbers. Normally I would use `seq`: ``` for i in `seq 1 10 15 20` #do stuff loop ``` But seemingly on this Solaris box `seq` does not exist. Can anyone help by providing another solution to iterating a list of numbers?

Original source