Jump to content

[Unix] a dos style rename wont work


Recommended Posts

Hey guys i'm creating a dos style rename script, so if a user types say q14.* as the 1st param and b14.* as the 2nd and will rename all q14 files to b14 but keep the extensions, so i've developed nearly the full script "i think", if i use echo(echo  "if $1 had been renamed it would now be $newfile") to simulate the rename it works fine shows

q14.1 will be renamed to b14.1

q14.2 will be renamed to b14.2


but it becomes a whole different story if i alter that line to  "mv $1 $newFile"


case $# in
0)echo Usage: dosRename file >&2
*)for file
                case $file in

                [A-Za-z0-9]*.*) type=main
                *.[A-Za-z0-9]* )type=extension
        #echo $type


        while [ $# -ne 1  ]
                case $type in
                'extension')    extension=`echo $endFile |sed -e 's/*././'`
                                newfile=`echo $1 |sed -e "s/.[A-Za-z0-9]*/$extension/"`
                                echo  "if $1 had been renamed it would now be $newfile"
                             #   mv $1 $newfile
                'main')         fileName=`echo $endFile | sed -e 's/.*//'`
                                newFile=`echo $1 | sed -e "s/[A-Za-z0-9]*.(.*[A-Za-z0-9]*)/$fileName.1/"`
                                echo "if $1 had been renamed it would now be $newFile"
                            #    mv $1 $newFile
                shift 1


it renames the 1st one fine then the rest go along the lines of

dosRename q14.* b14.*

it dose first one fine but 2nd one ends up q14.1.2 and third q14.1.2.3

any ideas what is up with my script?

Link to comment
Share on other sites

  • 3 weeks later...

you'd expect rn to have that kindof functionality anyway. cant say for certain that it does, cos i've never had to do that but as a rule *nix commands are alot more flexable than equivalent DOS commands.

dont even start on the spelling mistakes

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...