sean finney on 22 Feb 2006 15:44:08 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] bash script help needed


hi art,

as others have suggested, your problem is expansion of whitespace.

personally, from experience having learned the hardway, i suggest
you use a method that is immune to not only whitespace, but
other forms of shell expansion problems (like globbing or
variable expansion).

for example, if you want to do something on all files in a
directory, my preferred method is

find /dir -type f -print0 | xargs -0 do_something 

(various invocations of find can limit to certain directories, depths,
filenames, etc.  various invocations of xargs can limit the number of
args passed to a command, or placement of the args within a command)

so in your example i'd do the above, substituting do_something with
the rename command suggested by mct.  i guess that'd be something like

find /dir -type f -print0 | xargs -0 rename 's/\s+/_/g'

keep in mind that this may run the command on the same file multiple
times, but if you're just replacing some chars with others that
shouldn't make any difference.


	sean

Attachment: signature.asc
Description: Digital signature

___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug