Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!wuarchive!brutus.cs.uiuc.edu!uakari.primate.wisc.edu!uflorida!novavax!hcx1!brad From: brad@SSD.CSD.HARRIS.COM (Brad Appleton) Newsgroups: comp.unix.questions Subject: Re: Bourne Shell (/bin/sh) counting? Summary: What exactly was the question asker trying to do anyway Keywords: shell Message-ID: <3350@hcx1.SSD.CSD.HARRIS.COM> Date: 20 Mar 90 15:14:49 GMT References: <22788@adm.BRL.MIL> <63524@srcsip.UUCP> Sender: news@hcx1.SSD.CSD.HARRIS.COM Organization: Harris Computer Systems, Fort Lauderdale, FL Lines: 44 In article <22788@adm.BRL.MIL> rbottin@atl.calstate.edu (Richard John Botting) writes: >Jeff Asks >> What is the best way to provide a loop counter in a Bourne >> shell script? An example script is below, all it needs is >> the count incrementer. > >> #!/bin/sh >> count=0 >[...] >> # >> echo count=$count > ... > > [ points out significant details in using 'expr' ] > ... >I'd like to see a neat solution (other than a "increment.c" program). This is the easiest one yet (using the original example): #!/bin/sh count=0 for i in 1 2 3 4 5 6 7 ; do count=$i done Has the same effect as incrementing count (and is "plainer" too). Or better yet: #!/bin/sh count=7 I guess what Im really asking is: Why did the asker of the original question need to do the incrementing if the for loop was already incrementing a variable for him? I think if we knew this we could all provide some assistance in helping him find the "nicest" way to do it. +-=-=-=-=-=-= "... and miles to go before I sleep." -=-=-=-=-=-=-=-=-+ | Brad Appleton | Harris Corporation | | brad@ssd.csd.harris.com | Computer Systems Division | | ... {uunet | novavax}!hcx1!brad | Fort Lauderdale, FL USA | +-=-=-=-=-=- DISCLAIMER: I said it, not my company! -=-=-=-=-=-=-=-=-+