From owner-freebsd-questions Tue Jul 9 10: 4:26 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C89CA37B400 for ; Tue, 9 Jul 2002 10:04:23 -0700 (PDT) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3C34A43E42 for ; Tue, 9 Jul 2002 10:04:23 -0700 (PDT) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.12.5/8.12.5) id g69H4KwB006867; Tue, 9 Jul 2002 12:04:20 -0500 (CDT) (envelope-from dan) Date: Tue, 9 Jul 2002 12:04:20 -0500 From: Dan Nelson To: David Smithson Cc: FreeBSD-Questions Subject: Re: How do I repeat a command N times? Message-ID: <20020709170420.GD20718@dan.emsphone.com> References: <003101c22768$80ddb250$0801a8c0@customfilmeffects.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <003101c22768$80ddb250$0801a8c0@customfilmeffects.com> X-OS: FreeBSD 5.0-CURRENT X-message-flag: Outlook Error User-Agent: Mutt/1.5.1i Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG In the last episode (Jul 09), David Smithson said: > Hello friends. I want to repeat a command 607 times and stop. How do I > accomplish this besides writing a script that's 607 lines long? Lots of ways. for i in `jot 607` ; do mycommand done This gets unwieldy if you want to loop, say a million times, since the jot command creates a string made up of all the numbers separated by spaces. A bit more complicated, but scales better: i=1 while [ $i -le 607 ] ; do mycommand i=$((i+1)) done If you're using zsh, you can use repeat 607 ; do mycommand done , but it's not portable to all shells like the while loop. -- Dan Nelson dnelson@allantgroup.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message