From owner-freebsd-questions Sun Feb 7 23:45:27 1999 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id XAA28510 for freebsd-questions-outgoing; Sun, 7 Feb 1999 23:45:27 -0800 (PST) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from scientia.demon.co.uk (scientia.demon.co.uk [212.228.14.13]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id XAA28498 for ; Sun, 7 Feb 1999 23:45:23 -0800 (PST) (envelope-from ben@scientia.demon.co.uk) Received: from ben by scientia.demon.co.uk with local (Exim 2.11 #1) id 109bvq-0000QR-00; Sun, 7 Feb 1999 21:39:58 +0000 Date: Sun, 7 Feb 1999 21:39:57 +0000 From: Ben Smithurst To: root@isis.dynip.com Cc: freebsd-questions@FreeBSD.ORG Subject: Re: Help About Shell Script Message-ID: <19990207213957.A1306@scientia.demon.co.uk> References: <19990207133723.B71725@scientia.demon.co.uk> <199902071818.VAA63085@isis.dynip.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.95.1i In-Reply-To: <199902071818.VAA63085@isis.dynip.com> Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Please remember to cc all replies to the mailing list. root@isis.dynip.com wrote: > On 7 Feb, Ben Smithurst wrote: > > > i=0 > > while [ $i -le 1000 ]; do > > j=0 > > while [ $j -le 1000 ]; do > > ## do your stuff here with $i and $j > > > > j=$(($j+1)) > > done > > i=$(($i+1)) > > done > > Thanks very much. > What if we wanted to tke the variables i and j > from a file. That would depend what format the file was. At the simplest level, with two files called "current_i" and "current_j", containing the numbers alone, you can read that like so: i=$(cat current_i) j=$(cat current_j) and then proceed as normal. If the file contains something like i=5 j=18 you could probably do eval $(cat name_of_the_file) to get those variables as shell variables. If the file contains any more, you'll have to get something smarter to read it, and I'd recommend using Perl if you go much more complex. -- Ben Smithurst ben@scientia.demon.co.uk send a blank message to ben+pgp@scientia.demon.co.uk for PGP key To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message