From owner-freebsd-questions@FreeBSD.ORG Tue Feb 19 17:46:17 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EFD4216A417 for ; Tue, 19 Feb 2008 17:46:17 +0000 (UTC) (envelope-from kamikaze@bsdforen.de) Received: from mail.bsdforen.de (bsdforen.de [212.204.60.79]) by mx1.freebsd.org (Postfix) with ESMTP id A83CD13C442 for ; Tue, 19 Feb 2008 17:46:17 +0000 (UTC) (envelope-from kamikaze@bsdforen.de) Received: from mobileKamikaze.norad (nat-wh-1.rz.uni-karlsruhe.de [129.13.72.169]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.bsdforen.de (Postfix) with ESMTP id 7EB2C405486; Tue, 19 Feb 2008 18:46:16 +0100 (CET) Message-ID: <47BB15E7.1000907@bsdforen.de> Date: Tue, 19 Feb 2008 18:46:15 +0100 From: Dominic Fandrey User-Agent: Thunderbird 2.0.0.9 (X11/20080205) MIME-Version: 1.0 To: Paul Schmehl References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Cc: FreeBSD Questions Subject: Re: Shell scripting question - incrementing X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Feb 2008 17:46:18 -0000 Paul Schmehl wrote: > I could do this in perl easily, but I'm trying to force myself to learn > shell scripting better. :-) > > ... > > Once this file is created (or ideally *while* it's being created!) I > need to increment the sid numbers. The first one is 2000001. The > second needs to be 2000002, and so forth. I don't know the total > number of lines ahead of time, but it's easy enough to get after the > file is created. (wc -l file.rules | awk '{print $1}') > > Is there a way to do this in shell scripting? In perl I'd use a for > loop and vars, but I'm not sure how to solve this problem in shell > scripting. You can do simple integer arithmetics using expr. You'll have to realize this in a while loop: i=2000001 while [ $i -le $largest_i ]; do # insert code here i=`expr $i + 1` done