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
.



Relevant Pages

  • Re: Why newbies dont RTFM...
    ... Even though I've used Linux before, I've never had to do any ... > BASH BUILTIN COMMANDS ... > last command exited within ... > unless the shell is not exe‚ ...
    (comp.os.linux.misc)
  • Why newbies dont RTFM...
    ... Even though I've used Linux before, I've never had to do any ... BASH BUILTIN COMMANDS ... last command exited within ... unless the shell is not exe‚ ...
    (comp.os.linux.misc)
  • Re: how do I view previously typed commands in the csh ?
    ... I'm starting to like bash. ... It is another Bourne Shell ... appears to be the default shell on all the Linux boxen. ... to use either vi-like command editing like ksh. ...
    (comp.unix.solaris)
  • Re: BASH as root shell (static linking)
    ... BASH is not a UNIX shell. ... BASH occurred with Linux then carried over into FreeBSD. ... Use "tcsh" as a shell and let the linux community do whatever they want. ...
    (freebsd-questions)
  • Re: sed -f
    ... Better yet, us bash, like almost everyone else. ... The overwhelming majority, unix or linux, in my experience. ... It's the default shell on most linux distros and at least some ...
    (comp.unix.shell)