From owner-freebsd-questions@FreeBSD.ORG Sat Feb 19 17:05:55 2005 Return-Path: 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 98DFB16A4CE for ; Sat, 19 Feb 2005 17:05:55 +0000 (GMT) Received: from relay.pair.com (relay00.pair.com [209.68.1.20]) by mx1.FreeBSD.org (Postfix) with SMTP id EC89743D79 for ; Sat, 19 Feb 2005 17:05:54 +0000 (GMT) (envelope-from alejandro@varnet.biz) Received: (qmail 92761 invoked from network); 19 Feb 2005 17:05:54 -0000 Received: from unknown (HELO ale.varnet.bsd) (unknown) by unknown with SMTP; 19 Feb 2005 17:05:54 -0000 X-pair-Authenticated: 200.115.214.206 Date: Sat, 19 Feb 2005 14:06:27 -0300 From: Alejandro Pulver To: Scott Milliken Message-ID: <20050219140627.44f632b4@ale.varnet.bsd> In-Reply-To: <42175A14.3000402@e-comsultant.net> References: <20050219125559.3bb98715@ale.varnet.bsd> <42175A14.3000402@e-comsultant.net> X-Mailer: Sylpheed-Claws 0.9.12b (GTK+ 1.2.10; i386-portbld-freebsd5.3) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit cc: freebsd-questions@freebsd.org Subject: Re: How to handle numeric variables in sh? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 19 Feb 2005 17:05:55 -0000 On Sat, 19 Feb 2005 10:24:04 -0500 Scott Milliken wrote: > Here's a code snippet of a script I use often to number a bunch of pics > in a directory that I think shows how to do what you want to do: > > $PICNUM=100 > for FNAME in DSC*.JPG > do > NEWNAME=My_Pictures-$PICNUM.jpg > mv $FNAME $NEWNAME > PICNUM=$(($PICNUM+1)) > done > > This works in /bin/sh from my FreeBSD 4.11 system and also bash. If you > want to perform a mathematical operation on a shell variable, just > surround the expression with $(( expr )) and it'll work. > > Hope that helps. > > Scott Milliken > Thank You. Y saw the use of '$(( expr ))' some time ago in 'Advanced Bash Scripting Guide', but I thought it was only for 'bash'. I am using FreeBSD 5.3 and it also works in '/bin/sh'. Best Regards, Ale