Fblade1987 Posted April 17, 2008 Share Posted April 17, 2008 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 .....etc but it becomes a whole different story if i alter that line to "mv $1 $newFile" #!/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? Quote Link to comment Share on other sites More sharing options...
uber_tom Posted May 3, 2008 Share Posted May 3, 2008 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.