[TriLUG] Backup script... Spaces in path

Jeremy Portzer jeremyp at pobox.com
Mon Aug 11 09:24:44 EDT 2003


On Fri, 2003-08-08 at 12:54, Tom Woods wrote:
> I'm writing a backup script, learning as I go...  The problem I am having
> is backing up a Windows system via samba (although I don't think it being
> a Windows system has anything to do with this problem.)  When I pass a
> path  and filename with spaces via $1 or $n to the function, tar sees the
> space as a delimiter, not as a part of the path.  I have tried using ', ",
> and \<space>, nothing seems to work.  I'm sure someone out there knows how
> to accomplish what I need.
> 
> Also, any comments or suggestions about my script are welcome.  I am sure
> there are better ways to get the job done!  Yes, I'm a newbie, but I'm
> learning more and more as I go along.
> 

I know I'm replying late, as I was on vacation last week.
Another thing you might look into is using "find" instead of "ls" to
list files, and connecting it to a program like xargs.  With these two
programs (and many others), you can use an option similar to '-0' (dash
zero) that will use the NUL character to separate filenames.  (The NUL
is ASCII code 00, hence the "-0".) This way you avoid any problems if
the files have spaces, quotes, hyphens, or other strange characters.

For example, to find all files with "pizza" in them and remove them:

find -name '*pizza*' -print0| xargs -0 echo rm -f

(The above command actually just echos the rm command, it doesn't
actually perform it.)

You get the idea.  Check the man pages of other commands you wish to
use, as many support the NUL character thing.  But you can do most
anything by combining find and xargs like the above.

--Jeremy

-- 
/---------------------------------------------------------------------\
| Jeremy Portzer       jeremyp at pobox.com       trilug.org/~jeremy     |
| GPG Fingerprint: 712D 77C7 AB2D 2130 989F  E135 6F9F F7BC CC1A 7B92 |
\---------------------------------------------------------------------/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://www.trilug.org/pipermail/trilug/attachments/20030811/09250d18/attachment.pgp>


More information about the TriLUG mailing list