Re: Urgent: Need an integer for loop for renaming files

From: those who know me have no need of my name (not-a-real-address_at_usa.net)
Date: 03/02/04


Date: 02 Mar 2004 17:07:35 GMT

in comp.unix.shell i read:

>I need to have a script that will rename a bunch of files, while they are
>deposited in some directory.
>
>I want to keep 120 versions of the file. When a new file arrives (named
>file.ext) I need to rename all files in order to get
>file119.ext becomes file120.ext
>file118.ext becomes file119.ext and so on ending with file.ext becoming
>file1.ext

here's something a little easier on the eyes.

[note: you say file*.ext above and in part of your script, but the script
renames camN.jpg files and is called seq_histo_webcam, so i'm going to go
with the more concrete looking filenames -- if i've guessed wrongly it
should be easy enough for you to fix.]

  #!/bin/bash

  if [[ -f cam.jpg ]]
  then
      for ((seq=119; seq>0; seq--))
      do
          mv -f cam${seq}.jpg cam$((seq+1)).jpg
      done
      mv cam.jpg cam1.jpg
  fi

as for your script:

> seq=`expr $seq -1`

this is your problem, e.g.,

  $ expr 119 -1
  expr: syntax error

you need a space before the 1 and after the dash, i.e.,

                seq=`expr $seq - 1`

or something more modern, e.g.,

                seq=$((seq-1))
                ((seq--))
                let seq--

-- 
a signature


Relevant Pages

  • Re: Rename File Using Strring Found in File?
    ... OK, thanks, but the script does not seem to rename the files. ... # sleep 1; ... to the string in this particular file that I want to match. ...
    (comp.lang.perl.misc)
  • Re: rename a local group in windows 2003
    ... strComputer = objShell.ExpandEnvironmentStrings ... I tried to rename several local groups using the MoveHere method ... Didn't matter if I ran the script on the ... WinNT provider only rename domain groups, ...
    (microsoft.public.windows.server.scripting)
  • Re: Renaming a bunch of users with a script
    ... I have to rename ALL of my 17.000 users to convert name, surname, displayName and cn to uppercase!!! ... I made a script that changes the name, surname and displayName of all of the users, but at the same time that I change them I create an output file with the following information for every user ... Subdirec. ...
    (microsoft.public.windows.server.scripting)
  • Re: rename a local group in windows 2003
    ... If the script always runs on the computer where the local group is to be ... strComputer = objNetwork.ComputernName ... WinNT provider only rename domain groups, ...
    (microsoft.public.windows.server.scripting)
  • Re: Renaming computer and Account in Windows 2000
    ... reg merge from a netware login script before they join AD... ... here so any ideas how I just add the prefix to the existing name.. ... As soon as you rename it and reboot it, ... > the network completely unless you've got your DNS and/or WINS set up to cope ...
    (microsoft.public.win2000.setup_deployment)