Re: Mass renaming of files



On 2006-06-25, R. Kannan wrote:
Chris F.A. Johnson wrote:

On 2006-06-24, R. Kannan wrote:
Chris F.A. Johnson wrote:

On 2006-06-24, Handover Phist wrote:

I think you meant: A=$(( $A + 1 ))


Nope that does not work. You probably need..

A=1; for i in *.JPG; do mv $i file$A.jpg; A=`expr $A + 1`; done

I know of no shell generally available with Linux in which `expr $A
+ 1` will work and A=$(( $A + 1 )) will not. It will work with
bash, ash, dash, ksh, and pdksh (and zsh in POSIX mode).

You can get an old Bourne shell that doesn't do arithmetic from the
Heirloom Toolkit, but it is not part of any distribution.

It seems to work for me. (SuSE 9.0)

As it should. Both A=$(( $A + 1 )) and "A=`expr $A + 1`" should
work in any shell where "for in *.jpg" works (which is any except
[t]csh). The former is much faster.

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
.