Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!wrdis01!gatech!bloom-beacon!eru!hagbard!sunic!mcsun!corton!inria!cict!irit!cix.cict.fr From: pfeiffer@cix.cict.fr (Daniel Pfeiffer) Newsgroups: comp.unix.shell Subject: Re: for loops Keywords: sh, for, count Message-ID: <1477@irit.irit.fr> Date: 16 Apr 91 13:16:47 GMT Sender: pfeiffer@irit.fr Organization: Instituto de Reser^cado pri Informadiko de Tuluzo (IRIT) Universitato Paul Sabatier Lines: 56 What I don't like about the expr example, is the number of times we need to fork, since it's not a builtin. The following, adapted from a proposal one or two months back is a bit hard to understand, (documented at the end) but should be lots quicker: $ FILES=5 $ for i in `echo "[p 1 + d $FILES! do > echo $i > done 1 2 3 4 5 $ Someone also proposed a comparable script for awk, but, given that awk is a rather huge language, I suppose that dc is quicker. Alternately, for better readability, you might say count() { echo "[p 1 + d $1 !&2 exit 1 elif [ $# = 1 ]; then set 1 $1 fi # Program [ print top, increment top, duplicate, push end, pop and compare # two top values, reexecute P if not past end ] # store program as P, push beginning, load P, execute it echo "[p ${3-1} + d $2 ! -- Tolosa (Toulouse), Midi-Pyrenees, Europe -- "Beware - polyglot esperantist" -- N _---_ / \ NEWS, it goes around the world. W (-------) E (sorry, my bitmap doesn't have a world-class resolution) \_ _/ ---