Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!pencil.cs.missouri.edu!pencil!rich From: rich@pencil.cs.missouri.edu (Rich Winkel) Newsgroups: comp.unix.shell Subject: Re: for loops Keywords: sh: for i to $FILES Message-ID: Date: 5 Apr 91 22:33:00 GMT References: <3693@ux.acs.umn.edu> <1991Apr3.213023.23397@athena.mit.edu> Organization: UMC Math Dept. Lines: 26 jik@athena.mit.edu (Jonathan I. Kamens) writes: ]In article <3693@ux.acs.umn.edu>, edh@ux.acs.umn.edu (Merlinus Ambrosius) writes: ]|> In sh, I'd like to do something like a BASIC for loop. Say I have $FILES ]|> set to some number, and I'd like to go through a loop $FILES times. Can ]|> this be done in sh? ]Yes. The trick is getting from the number to that many items that you can put ]into a for loop. Something like this ] FILES=10 ] for i in `jot $FILES`; do ] echo -n "*" ] done; echo "" ]will print ten asterisks and then a newline, if your echo supports "-n" ]and you have "jot". If you don't have "jot", you can get it from ]/help/dist on lilac.berkeley.edu. .... How about this variation for those who don't have jot: FILES=10 for i in `head -$FILES /usr/dict/words` echo -n "*" done I guess someone's going to tell me now that 'head' isn't standard unix? Rich