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 -->
  #2 (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
This should work for you:

Code:
#!/bin/bash

VIDEO_ROOT_DIRECTORY="/Users/astrid/NFS/scripts/img2iso"

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

   while [ ! "$exit" ]
   do
      newname=`echo "$imgfile" | sed "s/\.img$/$suffix\.iso/"`
      if [ ! -f "$newname" ]
      then
         mv "$imgfile" "$newname"
         exit="y"
      else
         n="$((n+1))"
         suffix="-$n"
      fi
   done
done