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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Root Password change bullz26 SUN Solaris 2 03-30-2008 11:09 AM
How to change ROOT password. angelofhell HP-UX 3 02-25-2008 06:44 AM
change root password duke0001 SUN Solaris 3 02-22-2007 12:10 PM
how do i change extension kswaraj Shell Programming and Scripting 2 06-28-2004 08:07 PM
How to change extension? prkwan Shell Programming and Scripting 4 11-16-2002 07:14 PM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 02-15-2008
Astrid Astrid is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 4
change file extension from root and subdirectories

Hello, my first post!
I'd appreciate help with this script, I'm new to this.

I have a media directory where I want to batch convert image file names from .img to .iso.

I've tried but get:
$ ./img2iso2.sh
./img2iso2.sh: line 13: syntax error: unexpected end of file

This is my unfinished script:
Code:
#!/bin/bash

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

# Check if the directory exist or not
if [ -d "$VIDEO_ROOT_DIRECTORY" ]; then
	cd $VIDEO_ROOT_DIRECTORY
else
	print "ERROR: Unable to reach directory - or it does not exist!";
fi

for imgfile do 
    	case $imgfile *.img
            	do mv $imgfile.img $imgfile.iso;
               	done
          print "img-files renamed to iso";
    	esac
done

exit 0
I assume this doesn't check subdirectories, even though I'd like it to. Maybe a combination of find, grep and sed should be used instead? These commands seems to work marvels in almost any situation.

Also, I'd think it would be smart to include some sort of check:
if there is a file called image.iso and one called image.img in the same (sub)directory; I'd like to change the name of that .img file to image-1.iso. But I don't even know where to start with this check!

If I understand the error message there's a problem with quoting? I've made so many trials that I can't remember where I started anymore.

Any help is greatly appreciated.


EDIT:
Searching the forum I found a better way to do the replacement of the file extension (here), but I wasn't so lucky with the subdirs.

Last edited by Astrid; 02-15-2008 at 03:43 PM..
 

Bookmarks

Tags
linux, linux commands, unix commands

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:41 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0