Date: Tue, 19 Feb 2008 18:46:15 +0100 From: Dominic Fandrey <kamikaze@bsdforen.de> To: Paul Schmehl <pauls@utdallas.edu> Cc: FreeBSD Questions <freebsd-questions@freebsd.org> Subject: Re: Shell scripting question - incrementing Message-ID: <47BB15E7.1000907@bsdforen.de> In-Reply-To: <B4C4A8D8DF6EFE8801895F53@utd59514.utdallas.edu> References: <B4C4A8D8DF6EFE8801895F53@utd59514.utdallas.edu>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?47BB15E7.1000907>
