How to handle numeric variables in sh?

Scott Milliken scott.milliken at e-comsultant.net
Sat Feb 19 16:23:13 GMT 2005


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

Alejandro Pulver wrote:

>Hello,
>
>Is there a way to handle numeric variables (addition, multiplication, etc.) in 'sh' (or throught an external command)?
>
>Thanks and Best Regards,
>Ale
>_______________________________________________
>freebsd-questions at freebsd.org mailing list
>http://lists.freebsd.org/mailman/listinfo/freebsd-questions
>To unsubscribe, send any mail to "freebsd-questions-unsubscribe at freebsd.org"
>
>!DSPAM:42176184998836675110134!
>
>  
>



More information about the freebsd-questions mailing list