ubuntuusers.de

gutes rename skript-leider fehler

Status: Ungelöst | Ubuntu-Version: Nicht spezifiziert
Antworten |

alex1974

Anmeldungsdatum:
23. April 2007

Beiträge: 87

Wohnort: Wien 1060

Hallo,
habe beim Stöbern ein rename skript gefunden, das kompakt, aber wie ich finde sehr effektiv ist. Mein Problem, es funkt nicht richtig. Kann sich das mal wer ansehen, der was davon versteht.
Könnte auch für andere interessant sein, da diese rename Dinger immer wieder gefragt sind.

    #!/bin/sh
             # renna: rename multiple files according to several rules
             # written by felix hudson Jan - 2000
             # check: http://www.faqs.org/docs/Linux-HOWTO/Bash-Prog-Intro-HOWTO.html
             
             #first check for the various 'modes' that this program has
             #if the first ($1) condition matches then we execute that portion of the
             #program and then exit
             
             # check for the prefix condition
             if [ $1 = p ]; then
             
             #we now get rid of the mode ($1) variable and prefix ($2)
               prefix=$2 ; shift ; shift
             
             # a quick check to see if any files were given
             # if none then its better not to do anything than rename some non-existent
             # files!!
             
               if [$1 = ]; then
                  echo "no files given"
                  exit 0
               fi
             
             # this for loop iterates through all of the files that we gave the program
             # it does one rename per file given
               for file in $*
                 do
               #  mv ${file} $prefix$file
                  echo ${file} $prefix$file               
               done
             
             #we now exit the program
               exit 0
             fi
             
             # check for a suffix rename
             # the rest of this part is virtually identical to the previous section
             # please see those notes
             if [ $1 = s ]; then
               suffix=$2 ; shift ; shift
             
                if [$1 = ]; then
                 echo "no files given"
                exit 0
                fi
             
              for file in $*
               do
                mv ${file} $file$suffix
              done
             
              exit 0
             fi
             
             # check for the replacement rename
             if [ $1 = r ]; then
             
               shift
             
             # i included this bit as to not damage any files if the user does not specify
             # anything to be done
             # just a safety measure
             
               if [ $# -lt 3 ] ; then
                 echo "usage: renna r [expression] [replacement] files... "
                 exit 0
               fi
             
             # remove other information
               OLD=$1 ; NEW=$2 ; shift ; shift
             
             # this for loop iterates through all of the files that we give the program
             # it does one rename per file given using the program 'sed'
             # this is a sinple command line program that parses standard input and
             # replaces a set expression with a give string
             # here we pass it the file name ( as standard input) and replace the nessesary
             # text
             
               for file in $*
               do
                 new=`echo ${file} | sed s/${OLD}/${NEW}/g`
                 mv ${file} $new
               done
             exit 0
             fi
             
             # if we have reached here then nothing proper was passed to the program
             # so we tell the user how to use it
             echo "usage;"
             echo " renna p [prefix] files.."
             echo " renna s [suffix] files.."
             echo " renna r [expression] [replacement] files.."
             exit 0
             
             # done!

Danke,
Alex
moderiert user unknown hat geschrieben:

Code-Tags hinzugefügt. Bitte beim nächsten mal selbst Code markieren, und auf den Webbutton # drücken - danke.

alex1974

(Themenstarter)

Anmeldungsdatum:
23. April 2007

Beiträge: 87

Wohnort: Wien 1060

z.B. sollte das Programm, wenn man keine Optionen mitgibt den letzten Teil anzeigen. "Wie benutze ich das skript richtig". Aber es kommt auch ein Fehler einer Variable mit.

alex1974

(Themenstarter)

Anmeldungsdatum:
23. April 2007

Beiträge: 87

Wohnort: Wien 1060

OK, ich habe mich gespielt und man muß in der Zeile

# check for the prefix condition
if [ $1 = p ]; then

$1 und p in Hochkommata "" setzen.

alex1974

(Themenstarter)

Anmeldungsdatum:
23. April 2007

Beiträge: 87

Wohnort: Wien 1060

bleibt noch folgendes Problem

alex@alex-leisser:~$ renna r old new ~/.aMule/Incoming/
mv: Verschieben von „.aMule/Incoming/“ in eigenes Unterverzeichnis („.aMule/Incoming/Incoming“) nicht möglich

Ich finde den Fehler nicht.

Antworten |