UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old April 18th, 2008, 04:37 AM
fblade1987 fblade1987 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 1 fblade1987 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 56 sec
Reputation Power: 0
Dos style rename

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

Quote:
q14.1 will be renamed to b14.1
q14.2 will be renamed to b14.2
.....etc


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


Code:
#!/bin/sh

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

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

		endFile=$file

		while [ $# -ne 1  ]
		do
				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
					   ;;
				esac
				shift 1
		done
	   ;;

esac


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?

Reply With Quote
  #2  
Old April 28th, 2008, 02:50 PM
LKBrwn_DBA LKBrwn_DBA is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Posts: 292 LKBrwn_DBA User rank is Sergeant (500 - 2000 Reputation Level)LKBrwn_DBA User rank is Sergeant (500 - 2000 Reputation Level)LKBrwn_DBA User rank is Sergeant (500 - 2000 Reputation Level)LKBrwn_DBA User rank is Sergeant (500 - 2000 Reputation Level)LKBrwn_DBA User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 16 h 42 m 25 sec
Reputation Power: 9
Cool


Unless you provide the parameters in single quotes, they will be expanded!

Try:
Code:
dosRename 'q14.*' 'b14.*'


PS: I did not review your script, there may be other issues.


__________________

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Dos style rename


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway