The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 02-15-2008
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
  
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Very strange, I've tested the script with some dummy files and it works on my linux box.

Try inserting some echo commands in the script and try to re-run it:

Code:
#!/bin/bash

# Set the video directory here
VIDEO_ROOT_DIRECTORY="/Users/astrid/NFS/scripts/img2iso"

for imgfile in `find "$VIDEO_ROOT_DIRECTORY" -name "*.img" -type f`
do
   echo "Processing IMGFILE <$imgfile>"
   n=0
   exit=""
   suffix=""

   while [ ! "$exit" ]
   do
      newname=`echo "$imgfile" | sed "s/\.img$/$suffix\.iso/"`
      if [ ! -f "$newname" ]
      then
         echo "NEW NAME OK! Renaming to <$newname>"
         mv "$imgfile" "$newname"
         exit="y"
      else
         echo "NEW NAME <$newname> already exists! Incrementing suffix"
         n="$((n+1))"
         suffix="-$n"
      fi
   done
You can also run the script with "sh -x img2iso.sh" to trace the execution.