[K12OSN] Script Error with file names that have spaces

Jeff Kinz jkinz at kinz.org
Wed Sep 1 15:58:15 UTC 2004


On Wed, Sep 01, 2004 at 10:12:08AM -0500, Jim Kronebusch wrote:
> A while back I was provided the following script for changing
> permissions on files:



Put the $file in side double quotes  For example:

 chown -R $owner "$file"

Now the shell will see the entire string, including whitespace, as a
single argument.


So the new script looks like this:

 #!/bin/bash
 for file in /home/Drop/*
 do owner=$(ls -ld $file|awk '{print $3}')
 chown -R $owner "$file"
 Done


Step2 - 

Put the genie back in the bottle. :-) (lotsa luck!)

Encourage people to NEVER use spaces in their files names. I know its
more readable, but as you can see, its going to be very problematic, and
will break lots of existing tools.  Encourage them to use an underscore
instead.  

Wanna see how many files on the system already use spaces in their name?
find / -name "* *" 

Rename all files w/spaces under students home dirs - 

find /home/students -name "* *" -exec mv {}\ `echo {} | tr " " "_"` \&
(Not tested - just theory)

This breaks many applications which have files w/spaces in their names
as part of the package.  
DO NOT USE UNLESS YOU REALLY KNOW WHAT YOU ARE DOING!!!!!!


-- 
Linux/Open Source.  Now all your base belongs to you, for free.
============================================================
Idealism:  "Realism applied over a longer time period"

Jeff Kinz, Emergent Research, Hudson, MA.





More information about the K12OSN mailing list