Find & Replace

Joe(theWordy)Philbrook jtwdyp at ttlc.net
Mon Feb 27 01:01:01 UTC 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


It would appear that on Thu, Feb 23 2006, James Gray did say:

> The problem is that the "mv" command takes two arguments: the source and
> the destination, which are separated by a space.  So when you have a
> filename with a space in it you need to either escape the space or
> enclose the file name in quotes :)  Imagine I have the following file:
> Breath no More.mp3   (the song I'm listening to now - Evanescence)
> 
> to rename it you would have to take one of the following approaches: mv
> Breath\ no\ More.mp3 Breath_no_More.mp3  (escaping the spaces) mv "Breath
> no More.mp3" Breath_no_More.mp3  (using quotes)
> 
> Without explicitly telling the shell how to handle the spaces, the "mv"
> command interprets it like this:
> mv Breath no
> 
> Then complains that "Breath" doesn't exist - correct!  Enclosing file
> name operations in quotes is easily scriptable and safe way to handle
> weird file names from a script...unless the file name CONTAINS
> quotes....and that's a whole other kettle of fish!
> 
> I'll leave it there coz the corner cases (like quotes in filenames) are
> rare and not particularly easy to handle.  I hope you've enjoyed "Shell
> Scripting 101" :P

So you could just use an excellent tool like mc (apt-get install mc) which
lets you point at the undesirable file name, and type:
mv {esc}{enter} {esc}{enter}

then edit the automatically generated "\ " to "_" before hitting enter
again. mc does a great job with file names with quotes too... the below
quoted command line was generated this way, (though I did replace two
instances of "\ " with "_" 

> mv \"Fin\ Bus\"\ Rules.xls \"Fin_Bus\"_Rules.xls

Granted, this only works one file at a time, but it doesn't require the
user to understand scripting or count "\" to do...

Incidentally, I like your script, I'll be saving it for an "example" or
"how-to" but sometimes upper case characters ARE desired.

What would happen with the full automated version of your script if the
directory contained three different files named:
"good stuff" "GOOD STUFF" & "gooD stufF" ???

   #############################################################
   ##_if_you'd_prefer_an_clearsigned_".asc"_text_file_of_this_##
   ##message_as_an_mime_encoded_attachment,just_ask_me_while__##
   ##it's_STILL_IN_my_outbox_folder_._._._=+=+=+=+=+=+=+=+;-)_##
   #gpg sig for: Joe (theWordy) Philbrook DSA key ID 0x6C2163DE#
   # You can find my public gpg key at http://pgpkeys.mit.edu/ #
   #############################################################
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFEAk8IRZ/61mwhY94RAtkqAKCkYs6mjvMI9olS6lYBT0YgsRprMgCfWBv5
RQnR2dzJMF9/PlPKYnyGseM=
=xp/4
-----END PGP SIGNATURE-----
-- 
|  ~^~	 ~^~
|  <?>	 <?>		 Joe (theWordy) Philbrook
|      ^		      J(tWdy)P
|    \___/		   <<jtwdyp at ttlc.net>>





More information about the kubuntu-users mailing list